Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to grep on gdb print

Is there a way to grep on the output of print command in gdb? In my case, I am debugging a core dump using gdb and the object I am debugging contains hell lots of elements. I am finding it difficult to look for a matching attribute i.e:

(gdb) print *this | grep <attribute>

Thanks.

like image 431
Piyush Kansal Avatar asked Apr 11 '13 22:04

Piyush Kansal


People also ask

What does print do 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).

How do I redirect output to a file in gdb?

By default, GDB output will go to both the terminal and the logfile. Set redirect if you want output to go only to the log file. By default, GDB debug output will go to both the terminal and the logfile. Set debugredirect if you want debug output to go only to the log file.

Which command in gdb is used to find the type of variable?

The ptype [ARG] command will print the type. Show activity on this post. This question may be related: vtable in polymorphic class of C++ using gdb: (gdb) help set print object Set printing of object's derived type based on vtable info.

How do I get out of gdb in terminal?

To exit GDB, use the quit command (abbreviated q ), or type an end-of-file character (usually C-d ). If you do not supply expression , GDB will terminate normally; otherwise it will terminate using the result of expression as the error code.


1 Answers

You can use pipe command

>>> pipe maintenance info sections | grep .text
 [15]     0x5555555551c0->0x5555555554d5 at 0x000011c0: .text ...

>>> pipe maintenance info sections | grep .text | wc 
      1      10     100
like image 167
mug896 Avatar answered Nov 26 '22 12:11

mug896