Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing Front End for GDB

I want to write a GUI based debugger wrapped over GDB. Because, I dont want the program to stop after watch points or break points. Instead, it should redirect the details like filename, line number, new value and stuffs to a file and continue execution.

I am pretty bad at scripting. So, I want some starting point to start developing front end for GDB. As far as I googled, this link http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_node/gdb_211.html is not much understandable for a beginner in this activity?

Hopefully, I will get help on development in C/C++.

like image 397
Saran-san Avatar asked May 27 '13 10:05

Saran-san


People also ask

Is there a GUI for GDB?

KDbg is a graphical user interface to gdb, the GNU debugger. It provides an intuitive interface for setting breakpoints, inspecting variables, and stepping through code. KDbg requires KDE, the K Desktop Environment, but you can of course debug any program.

What is Gdbgui?

gdbgui is a browser-based frontend to gdb , the gnu debugger. You can add breakpoints, view stack traces, and more in C, C++, Go, and Rust! It's perfect for beginners and experts. Simply run gdbgui from the terminal to start the gdbgui server, and a new tab will open in your browser.

How do I list breakpoints in GDB?

You can see these breakpoints with the GDB maintenance command `maint info breakpoints' . Using the same format as `info breakpoints' , display both the breakpoints you've set explicitly, and those GDB is using for internal purposes. Internal breakpoints are shown with negative breakpoint numbers.

What is VisualGDB?

VisualGDB extends Visual Studio by adding seamless support for embedded devices. VisualGDB focuses on improving developer productivity through automating common setup tasks and includes an embedded-friendly IntelliSense engine, advanced debugger, profiler, static and dynamic code analyzers. Supported Devices.


1 Answers

For writing a GDB frontend, you indeed want to use the GDB/MI protocol but perhaps read this up-to-date copy instead of the older one you linked to.

Sample GDB/MI session

(Lightly edited version of this section from the GDB manual)

Launching GDB with the MI Command Interpreter

$ gdb -q --interpreter=mi2
=thread-group-added,id="i1"
(gdb)

File /bin/true

-file-exec-and-symbols /bin/true
^done
(gdb) 

Break main

-break-insert main
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x00000000004014c0",func="main",file="true.c",fullname="/usr/src/debug/coreutils-8.17/src/true.c",line="59",times="0",original-location="main"}
(gdb) 

Run and Breakpoint Hit

-exec-run
=thread-group-started,id="i1",pid="2275"
=thread-created,id="1",group-id="i1"
^running
*running,thread-id="all"
(gdb) 
=library-loaded,id="/lib64/ld-linux-x86-64.so.2",target-name="/lib64/ld-linux-x86-64.so.2",host-name="/lib64/ld-linux-x86-64.so.2",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/lib64/libc.so.6",target-name="/lib64/libc.so.6",host-name="/lib64/libc.so.6",symbols-loaded="0",thread-group="i1"
=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x00000000004014c0",func="main",file="true.c",fullname="/usr/src/debug/coreutils-8.17/src/true.c",line="59",times="1",original-location="main"}
*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame={addr="0x00000000004014c0",func="main",args=[{name="argc",value="1"},{name="argv",value="0x7fffffffde98"}],file="true.c",fullname="/usr/src/debug/coreutils-8.17/src/true.c",line="59"},thread-id="1",stopped-threads="all",core="1"
(gdb) 

Continue

-exec-continue
^running
*running,thread-id="1"
(gdb) 
=thread-exited,id="1",group-id="i1"
=thread-group-exited,id="i1",exit-code="0"
*stopped,reason="exited-normally"

Quitting GDB

(gdb) 
-gdb-exit
^exit

Existing GDB/MI Clients

There are several GDB/MI client implementations in C, C++, Java, Python. I'll list a few that I find easy to read:

  • The inactive libmigdb project (sample program, public interfaces) -- The good news is that it's an attempt at creating a reusable C library. The bad news is that it's not well maintained, e.g. I think it's missing GDB non-stop mode and catchpoint commands support, features that your use case would likely need.
  • python-gdb-mi -- Quite readable if you know Python
  • The C++ GDB/MI client code in QtCreator -- Also quite readable though it's written as part of an abstraction layer to support multiple debugger engines.

You might want to also browse this list of GDB frontends.

like image 180
scottt Avatar answered Sep 23 '22 06:09

scottt