Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print pointer content in GDB?

Tags:

gdb

In GDB I am trying:

gdb> p/s *0x0804b680

Which gives me:

$6 = 0x6c627550

Clearly it should have printed out lbruP, or am I wrong?

like image 917
drum Avatar asked Feb 02 '13 06:02

drum


People also ask

How do I print the value of a pointed pointer?

Printing pointers. You can print a pointer value using printf with the %p format specifier. To do so, you should convert the pointer to type void * first using a cast (see below for void * pointers), although on machines that don't have different representations for different pointer types, this may not be necessary.

What is print command in gdb?

The usual way to examine data in your program is with the print command (abbreviated p ), or its synonym inspect . It evaluates and prints the value of an expression of the language your program is written in (see section Using GDB with Different Languages).

What is Backtrace in gdb?

A backtrace is a summary of how your program got where it is. It shows one line per frame, for many frames, starting with the currently executing frame (frame zero), followed by its caller (frame one), and on up the stack.

How do you call a function in gdb?

The simplest is to cast the call to the function's declared return type. For example: (gdb) p getenv ("PATH") 'getenv' has unknown return type; cast the call to its declared return type (gdb) p (char *) getenv ("PATH") $1 = 0x7fffffffe7ba "/usr/local/bin:/"...


1 Answers

for char* p = "abcde";

do

p /s p 

e.g. not *p

(gdb) p /s p
$9 = 0x40060c "abcde"

If your p is not of type char* (e.g, void* v = p ) you can cast it or use the x command

(gdb) p /s (char*)v
$7 = 0x40061c "abcde"
(gdb) x /s v
0x40061c:    "abcde"
like image 110
eran Avatar answered Nov 03 '22 16:11

eran