Author Topic: Faster way to remote debug  (Read 1575 times)

bremenpl

  • Community Member
  • Posts: 62
  • Hero Points: 0
  • microcontrollers <3
Faster way to remote debug
« on: March 03, 2014, 12:57:25 pm »
Hello there,
Every time i want to do a remote debugging using my Jlink i have to manualy go to debug -> attach debugger -> GDB-> attach to remote process (GDB) and then click OK to choose my program.

Is there a faster 1 clicker way? Maybe some macro? Any help would be really aprichiated!

JakeMontgomery

  • Community Member
  • Posts: 79
  • Hero Points: 8
Re: Faster way to remote debug
« Reply #1 on: March 03, 2014, 04:59:48 pm »
I also do a lot of remote debugging. The solution I used was to create a custom macro. The part you are interested in seems to be starting the attached debugger. For that, I have a macro that calls the SE routine debug_remote(). I call it like:
Code: [Select]
int ret = debug_remote("gdb", debug_attach_info, dbg_get_session_name(dbg_get_current_session()));debug_attach_info is a custom string that describes the file to be debugged, and the various SE remote debugging settings. Since it is not really well documented in the SE help, you best bet is probably to temporarily modify the debug_attach_info() routine in debug.e to print the value, then run a session like you normally do, and reverse engineer from there.

Since remote debugging is a large party of my business, I have actually automated the entire process. My code is customized to my use cases, and definitely not in any shape to publish, but I will describe what it does. First I added a number of environment variables to Project->Project Properties->Open. These describe the remote file to be debugged, the target address, etc, etc. I have a "debug remote" SE macro which does the following:
  • Gets the environment variables using get_env()
  • Calls the SE  command shell(command_str, "PA") to start gdbserver on the remote machine. I use a "command_str" that uses plink, since my host is Windows, but you could probably use ssh on linux.
  • It then calls the SE command concur_command(exe_command_str) to copy the remote executable to the local machine. exe_command_str uses sftp to transfer the file. Since the transfer occurs asynchronously, I append  " && echo ":+ _chr(1) :+"jrm_debug_remote_transfer_done";   to the exe_command_str. This will cause SE to run the SE command (macro) jrm_debug_remote_transfer_done() once the transfer is complete.
  • In jrm_debug_remote_transfer_done() I actually just call jrm_start_debug_timer = _set_timer(100, _jrm_start_debug_timer_cb);. Where jrm_start_debug_timer is a global variable. I don't honestly recall why I added this 'delay', but it was in response to some problem. (That may not even exists of the current version of SE.)
  • The routine _jrm_start_debug_timer_cb() just makes the timer a 'one shot' like this: _kill_timer(jrm_start_debug_timer);_jrm_start_attach();
  • Finally the macro jrm_start_attach() calls debug_remote() as described at the start of this post.

It is a bit complicated to write and get setup, but now I am able to start remote debugging any of my projects with single kerystroke.

Good luck.

bremenpl

  • Community Member
  • Posts: 62
  • Hero Points: 0
  • microcontrollers <3
Re: Faster way to remote debug
« Reply #2 on: March 04, 2014, 06:30:41 am »
It is a bit too complicated indeed. I dont need to start the remothe server like that, im using jlink. Do you think you could share the macro code just for starting the certain remote debug session?

JakeMontgomery

  • Community Member
  • Posts: 79
  • Hero Points: 8
Re: Faster way to remote debug
« Reply #3 on: March 04, 2014, 01:04:41 pm »
For just starting a remote debugging session, the debug_remote() call described at the start of my original post is all you need. The code is:

Code: [Select]
int ret = debug_remote("gdb", debug_attach_info, dbg_get_session_name(dbg_get_current_session()));
Although, like I said, debug_attach_info is a string that you will need to craft yourself.

bremenpl

  • Community Member
  • Posts: 62
  • Hero Points: 0
  • microcontrollers <3
Re: Faster way to remote debug
« Reply #4 on: March 07, 2014, 12:31:27 pm »
Would you mind sharing an example of the debug_attach_info string? I opened the debug.e but i found no such function there.I have to say im a bit confised about this.

Edit: I found the function _command int debug_remote and tried to add as the first line:
Code: [Select]
debug_message(attach_info);
But i cannot save the file, it is protected. Is this the case anyway?
« Last Edit: March 07, 2014, 12:45:34 pm by bremenpl »

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2332
  • Hero Points: 308
Re: Faster way to remote debug
« Reply #5 on: March 07, 2014, 01:00:56 pm »
Or you can keep it simple and use SlickEdit's macro recording facilities to get where you are going.

Macro > Record Macro
Debug > Attach Debugger > GDB > Attach to Remote Process...
[cancel]
Macro > Stop Recording Macro
Name the macro, something like "debug_attach_gdb_remote"
Hit "Save and Bind to key"
Select the key you want to use to bring up GDB remote debugging.

You can also customize a toolbar and add a button that calls this macro.

bremenpl

  • Community Member
  • Posts: 62
  • Hero Points: 0
  • microcontrollers <3
Re: Faster way to remote debug
« Reply #6 on: March 07, 2014, 01:08:38 pm »
I dont understand the [cancel] part. Do i have to activate my debug session?
Edit: Ok i got to the point where i got the remote debug window open and i only have to click enter. I think thats close enough, but can Ok button be clicked as well?
« Last Edit: March 07, 2014, 01:11:59 pm by bremenpl »

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2332
  • Hero Points: 308
Re: Faster way to remote debug
« Reply #7 on: March 07, 2014, 01:39:58 pm »
The [cancel] part just means that you should hit Cancel.  You only want to record a macro to bring up the dialog.  The dialog history will have your last entries.  You can use F7/F8 to cycle through previous dialog history.