6

Is there a way to execute function in process core context in GDB?

The incentive is to run a function that will go through a large tree to find a specific node. I can walk the tree manually but I would like to build a function that will help me analyze the core.

Hence either a function or "GDB script" to run over the data tree.

Hagai
  • 969
  • 10
  • 13
  • Related question: (use pretty printer): [c++ - gdb pretty printing with direct function calls - Stack Overflow](https://stackoverflow.com/questions/8578320/gdb-pretty-printing-with-direct-function-calls) – user202729 Mar 10 '22 at 02:10

2 Answers2

4

Is there a way to execute function in process core context in GDB?

No: you need a "live" inferior process for that.

I can walk the tree manually but I would like to build a function that will help me analyze the core.

You can do that using Python scripting built into recent GDB versions.

Employed Russian
  • 182,696
  • 29
  • 267
  • 329
2

gdb can call C functions. If you type p myfunction(...parameters...), gdb will evaluate the expression and print the returned value. Of course, the program you're debugging must be stopped.

unwind
  • 378,987
  • 63
  • 458
  • 590
Giuseppe Guerrini
  • 4,102
  • 16
  • 29