Search code examples
linuxemacsgdbcross-platformxemacs

How can I run gdb in xemacs for cross-compiled code?


I don't use emacs, but I know xemacs can be used as a front-end for gdb (used it before). However, my code is cross-compiled, so I can't run gdb, I have to run a specific version of gdb that's for the cross-compiled code (let's call it gdb-foo). How do I set xemacs up to run the alternate gdb?

When I use M-x, gdb I get the prompt:

Run gdb on file:

I remember seeing something like this:

Run gdb like this:

But I don't know how to get that.

Next, once I learn how to do it this way, how can I do it as a one-liner I can run from bash, including gdb-foo and attach options? (I know bash scripting; I just need the incantation for xemacs.)


Solution

  • The idea is to change gdb executable. Let's see how to retrieve this kind of information using emacs.

    Under emacs, you can do C-h f gdb to print gdb function help:

    gdb is an interactive autoloaded compiled Lisp function in
    ‘gdb-mi.el’.
    
    It is bound to <menu-bar> <tools> <gdb>.... etc.
    

    Then click on gdb-mi.el to go to the lisp source. From there you can search for "executable" (C-s executable, then C-s for next occurrence). You will find this customizable variable:

    (defcustom gud-gdb-command-name "gdb -i=mi"
      "Default command to execute an executable under the GDB debugger."
      :type 'string
      :group 'gdb)
    

    And that's it! You have all the information you need.

    Now to effectively change gdb to gdb-foo, run the customize command: M-x customize. Then type "gud-gdb-command-name" in the search field + return. You should get something like:

    gud-gdb-command-name                              Search 
    
    Operate on all settings in this buffer:
     Revert...   Apply   Apply and Save 
    
    Hide Gud Gdb Command Name: gdb -i=mi      <---- MODIFY ME!
        State : STANDARD.
       Default command to execute an executable under the GDB debugger.
    Groups: Gdb
    

    You can modify "gdb -i=mi" to "gdb-foo -i=mi" then "Apply" or "Apply and Save".