开发者

GDB If statement return values?

开发者 https://www.devze.com 2023-02-21 10:57 出处:网络
Is there a way I can read开发者_如何学C if statements being evaluated? I mean, like get the return value of realpath in-

Is there a way I can read开发者_如何学C if statements being evaluated? I mean, like get the return value of realpath in -

if(realpath(path.c_str(), realPath) == 0)


You can step into and finish realpath function. The returned value will be printed on screen.


at the gdb prompt (if you got debug symbols enabled when you compiled)

print realpath(path.c_str(),realPath)

it will print the result, very nifty.


If you had a memory pointer laying around on your code, you could use GDB to allocate new memory space for it it, and use it to store the result of the expression you want to evaluate.

Check this page for more info.

(gdb) set variable p = malloc(sizeof(int))

(gdb) print p
$2 = (int *) 0x40013f98    (address allocated by malloc)

(gdb) set variable *p = 255

(gdb) print *p
$3 = 255
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号