Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7167897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:40:10+00:00 2026-05-28T14:40:10+00:00

Is it possible to control gdb from the debugged program? I’m hoping for a

  • 0

Is it possible to control gdb from the debugged program? I’m hoping for a library that can help with this, ideally with an API such as gdb_sendcmd("bt"), but I can live with something like connecting to local gdb via a socket.

Primary use case is programmatically adding a data breakpoint to monitor when a certain memory address next gets modified. Target language is, naturally, C; anything applicable to it can be reused with C++ and Objective-C.


Answer from Employed Russian has solved my direct problem, but I’d still love to know how I can run GDB commands programmatically from the debugged program. It may speed up some debugging if I could simply add code to the project instead of writing extra startup commands for GDB that would create breakpoints with attached commands.

So if there is a way to run commands programmatically, I’d still love to hear it 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:40:12+00:00Added an answer on May 28, 2026 at 2:40 pm

    The Python interface exported by GDB allows you to do many things. Maybe something like this would fit your requirements:

    import gdb
    
    CMD_FCT  = "gdb_run" 
    CMD_NAME = "str"
    
    class GdbRunBreakpoint(gdb.Breakpoint):
        def __init__(self):
            gdb.Breakpoint.__init__(self, CMD_FCT, internal=1)
            self.silent = True
    
        def stop(self):
            cmd = gdb.parse_and_eval(CMD_NAME).string()
            gdb.execute(cmd)
            return False
    GdbRunBreakpoint()
    

    (just write than in a file, and source it from your .gdbinit file)

    and on the application side:

    void gdb_run(char *str) {}
    
    
    int main () {
        gdb_run("where");
    }
    

    I think the code is straight forward, but as I mentioned in https://stackoverflow.com/a/8884512/341106, not everything is allowed in the stop callback, GDB is in an intermediate state, but many things will work as expected.

    EDIT: needless to say, this won’t work if you app is not compiled with debug symbols!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: DateTime.TryParse century control C# I have a C# app that's importing data
Possible Duplicate: Cross-thread operation not valid: Control accessed from a thread other than the
How can I control the value of the top-level this variable when running a
Is it possible to control another process' dialog from code? I want to answer
Is it possible to control the format of the password that is automatically generated
Is there a way I can control columns from code. I had a drop
I've written a plug-in that constructs a rich UI control. I'm hoping that there's
Is it possible to control SD card reader register pins from Linux via C/C++
Possible Duplicate: Cross-thread operation not valid: Control accessed from a thread other than the
Is it possible to control the Tools->Options->View->View Whitespace between pages through VBA/Macros? Thanks.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.