Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run an executable with command line options? #88

Open
cody-addison opened this issue May 24, 2019 · 12 comments
Open

How to run an executable with command line options? #88

cody-addison opened this issue May 24, 2019 · 12 comments
Labels
question Further information is requested

Comments

@cody-addison
Copy link

I apologize if this has already been discussed somewhere, but I couldn't find any mention of it. I'm trying to debug a C++ application using lldb and need to pass command line options to the application for debugging. How do I do this?

My config is
(dap-mode 1)
(dap-ui-mode 1)
(require 'dap-gdb-lldb)

When I run dap-debug, it asks for the executable to debug and starts a session, but I'm not able to run it with options.

@yyoncho
Copy link
Member

yyoncho commented May 24, 2019

Take a look at https://github.com/WebFreak001/code-debug/blob/master/package.json#L72 . It lists all arguments that you can pass to the debug adapter. Then in dap-mode you could do M-x dap-debug-edit-template and specify all params listed in code-debug execute the register call and the template will be registered and accessible via dap-debug. We need better support/documentation at dap-mode side for each adapter, but it is not possible to keep up with each one so we rely on the debug adapter users to help.

@yyoncho yyoncho added the question Further information is requested label May 24, 2019
@cody-addison
Copy link
Author

Thanks for the tip. I was able to edit the configuration and have the executable run. However now it just runs to completion without giving me a chance to set breakpoints. Is there a way to load the executable without immediately running it?

@yyoncho
Copy link
Member

yyoncho commented May 24, 2019

You should be able to place the breakpoints before starting the program or you are asking something else? AFAIK native debug have some limitations, you may read about them in its readme.

@cody-addison
Copy link
Author

I am trying to place breakpoints before starting the program. I run dap-debug and select my template and then the program executes and runs to completion. When in the process would I set the breakpoints?

Do you recommend I follow the instructions for LLDB here: https://github.com/emacs-lsp/dap-mode#lldb instead of the native debug solution?

@yyoncho
Copy link
Member

yyoncho commented May 25, 2019

I am trying to place breakpoints before starting the program. I run dap-debug and select my template and then the program executes and runs to completion. When in the process would I set the breakpoints?

You could do dap-breakpoint-toggle/add/remove or click in the fringe before starting the application. AFAIK Native debug has this limitation:

"Adding breakpoints while the program runs will not interrupt it immediately. For that you need to pause & resume the program once first. However adding breakpoints while its paused works as expected."

And also it does work with multiple threads.

Do you recommend I follow the instructions for LLDB here: https://github.com/emacs-lsp/dap-mode#lldb instead of the native debug solution?

IMO in the long term, it will be the prefered solution since that debug adapter is implemented by lldb team. There is one more debug adapter for lldb which I think will work much better ATM but we do not have integration with it: https://github.com/vadimcn/vscode-lldb . But like I mentioned I am not using this debug adapter and I cannot tell for sure.

@bjc
Copy link

bjc commented Sep 26, 2019

Then in dap-mode you could do M-x dap-debug-edit-template and specify all params listed in code-debug execute the register call and the template will be registered and accessible via dap-debug.

I can't understand these instructions. Does this mean that in the template I'm editing, if I wanted to change the gdb executable used, I can add :gdbpath "/usr/bin/gdb-multiarch"?

To be extremely specific: I need to launch /usr/bin/gdb-multiarch rather than the default gdb as specified in the the vscode extension.

I've tried

(dap-debug (list :type "gdb"
                 :request "launch"
                 :name "gdb-multiarch"
                 :dap-server-path dap-gdb-lldb-debug-program
                 :gdbpath "/usr/bin/gdb-multiarch"
                 :target "/home/bjc/src/MyStuff/bleusb/target/thumbv6m-none-eabi/release/usb"
                 :cwd "/home/bjc/src/MyStuff/bleusb/usb"))

and it seems to still launch the default gdb.

@bjc
Copy link

bjc commented Sep 26, 2019

After trying again, it turns out that setting :gdbpath does, indeed, work. I'm not sure what trouble I was having before.

@nbfalcon
Copy link
Member

Put a breakpoint in main and debug as usual. To find main, you can use helm-lsp-workspace-symbol or lsp-ivy-worskspace-symbol.

@EgorDuplensky
Copy link

EgorDuplensky commented Apr 1, 2022

Take a look at https://github.com/WebFreak001/code-debug/blob/master/package.json#L72 . It lists all arguments that you can pass to the debug adapter. Then in dap-mode you could do M-x dap-debug-edit-template and specify all params listed in code-debug execute the register call and the template will be registered and accessible via dap-debug. We need better support/documentation at dap-mode side for each adapter, but it is not possible to keep up with each one so we rely on the debug adapter users to help.

@yyoncho Is there any better way to do so?
Imagine a use case when you are debugging binary with all kind of different command line parameters, for example some unit test binary when the test name is passed as command line argument.
Native emacs gud interface allows you to provide all the arguments dynamically (also keeping the history), without updating a configuration file.
Is there any chance this will be implemented for dap?
like some dap-debug-custom command, when you pass the arguments interactively?

@yyoncho
Copy link
Member

yyoncho commented Apr 2, 2022

@EgorDuplensky you can build whatever flow you want creating a wrapper over dap-debug.

Here is sample one:

(defun my/debug ()
  (interactive)
  (dap-debug
   (list :type "cppdbg"
         :request "launch"
         :name "cpptools::Run Configuration"
         :MIMode "gdb"
         :program (read-file-name "Enter the binary to debug...")
         :cwd "${workspaceFolder}"
         :environment [])))

(note how :program is populated interactively).

@yyoncho
Copy link
Member

yyoncho commented Apr 2, 2022

@EgorDuplensky in general what I do is to create the configurations I need and then I use dap-debug-recent/dap-debug-last to pick the right one.

@EgorDuplensky
Copy link

EgorDuplensky commented Apr 2, 2022

@EgorDuplensky you can build whatever flow you want creating a wrapper over dap-debug.

Here is sample one:

(defun my/debug ()
  (interactive)
  (dap-debug
   (list :type "cppdbg"
         :request "launch"
         :name "cpptools::Run Configuration"
         :MIMode "gdb"
         :program (read-file-name "Enter the binary to debug...")
         :cwd "${workspaceFolder}"
         :environment [])))

(note how :program is populated interactively).

Thank you for the code example. This is actually almost exactly what I have in my emacs config (except your version is much cleaner than mine).
I was trying to say that this is pretty common use case and this is a bit strange dap mode doesn't have it as part of the general feautes / workflow. What do you think?
As for me I am not confident enough in my elisp skills to create a PR for this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants