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
  • 1,049
  • 11
  • 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
  • 199,314
  • 34
  • 295
  • 362
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
  • 391,730
  • 64
  • 469
  • 606
Giuseppe Guerrini
  • 4,274
  • 17
  • 32