Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/C++ Linux GDB API [closed]

Tags:

c++

c

linux

gdb

I want to make me a small GUI version of the GDB command line program on Linux to make debugging of small C programs more easier. There may exists already some especially in IDEs but I want to make it for fun and get better known to GDB.

Now I wanted to know whether GDB has a API so I can access GDB commands directly from code and I don't have to make a detour through the terminal for example with popen.

If there does not exists such a API from GDB, whats the simplest way to start GDB hidden and send commands to it, retrieve outputs from it?

like image 406
Michael Avatar asked Oct 03 '15 09:10

Michael


People also ask

What does GDB command do in Linux?

GNU Debugger, also known as gdb, allows us to sneak through the code while it executes or what a program was trying to do at the moment before it crashed. GDB basically helps us to do four main things to catch flaws in the source code. Start the program, specifying arguments that may affect the general behavior.

Can you run GDB with Valgrind?

Specifying --vgdb-error with any value also enables --vgdb=yes , which is required for using GDB with Valgrind. Note that Valgrind provides instructions for starting GDB as well as the command to use in order to connect GDB with Valgrind.

What is the difference between Valgrind and GDB?

The GNU Debugger (GDB) allows you to pause a running program and inspect its state. Valgrind's memcheck monitors a program's memory accesses and prints warnings if the program accesses invalid locations or attempts to read values that the program never set (initialized).


1 Answers

Many IDEs such as Eclipse and KDevelop use GDB MI (Machine Interface). It is line based machine oriented text interface to GDB. See full list here: https://sourceware.org/gdb/wiki/GDB%20Front%20Ends.

See these links to get started with GDB MI:

  • https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI.html
  • http://www.ibm.com/developerworks/library/os-eclipse-cdt-debug2/
like image 57
ks1322 Avatar answered Sep 25 '22 13:09

ks1322