hugsy / gef-extras

Extra goodies for GEF to (try to) make GDB suck even less
https://hugsy.github.io/gef-extras
MIT License
149 stars 50 forks source link

Execute GDB nexti Without Context Refresh #16

Closed H0r53 closed 4 years ago

H0r53 commented 5 years ago

I'm writing a GEF extension to execute a number of instructions (specified via arguments) and perform some profiling on the binary during that time based on the instruction pointer, register values, location within the binary, and etc. Everything is working well, except for after executing a number of nexti or stepi instructions via gdb.execute("nexti",to_string=False) the GEF context repaints itself a number of times equal to the number of instructions that were executed. This makes it difficult to view the results of my custom profiling command. I temporarily disabled all the context windows I could with set_gef_setting("context.layout",...) but there are still blank lines produced for each instruction that executes. This is surely because of an attempted repaint that is triggered after nexti/stepi. If I execute a large number of instructions (say over 100) then retrieving my profiling results is a major pain. I could write to another file but I'd prefer to show results within the primary context window itself. Any suggestions?

hugsy commented 5 years ago

To turn off the context, use gef config context.enable 0, it's all in the documentation. You should also remember that GDB adds it's own text when a breakpoint is hit. But you can always disable GDB logging too (see the doc).

Cheers,

H0r53 commented 5 years ago

This issue is not turning off context. That much is easy and yes it is in the documentation. The issue is, after turning off context and executing a series of gdb commands such as "step", the context attempts to repaint itself (after each step) - however since context is turned off a series of empty lines (with a large underscore) appears on the screen. If context is turned off and many step commands are executed then this clusters the screen with a large amount of blank lines, which is undesirable. To reproduce: 1) turn off context with gef config context.enable 0 2) execute "step" command 3) repeat step 2 around 10 times

Notice the series of blank lines, which is undesirable for extensions that attempt to display statistics after running a series of commands that adjust the instruction pointer (such as step).

hugsy commented 5 years ago

To reproduce:

  1. turn off context with gef config context.enable 0
  2. execute "step" command
  3. repeat step 2 around 10 times

I've followed your repro steps on fresh Ubuntu & Fedora VMs and got this:

Notice the series of blank lines, which is undesirable for extensions that attempt to display statistics after running a series of commands that adjust the instruction pointer (such as step).

I do not observe any blank line, and what I obtain is the intended behavior. If the context is disabled, the context command returns immediately, nothing is executed (see https://github.com/hugsy/gef/blob/dev/gef.py#L7237). I'm guessing there must be something wrong on your setup. Have you tried on a different (new) environment?

Also note that the extra lines such as

240     in ../csu/libc-start.c

in the output from above, are produced by GDB, not GEF.

H0r53 commented 4 years ago

I apologize for the delay in responding. Your very last statement ... the output from above, are produced by GDB, not GEF clarifies the issue I was experiencing. I suppose there is no way around this. I was hoping to programmatically execute multiple instructions without generating excess output.