Author Topic: Attach to running process from command line  (Read 6534 times)

rubenhak

  • Community Member
  • Posts: 6
  • Hero Points: 0
Attach to running process from command line
« on: February 14, 2013, 11:35:27 PM »
Hi,

I'm trying to attach to running process using slickedit in an automated way without going into a menu. I would have the PID of the process and the path to the binary path. It is ok if I would need to start a new slickedit process. Also, it would be useful to know if it is possible to analyse the core file by passing path to core and binary from command line.

Please let me know if there is a way to do this.

Thanks,
Ruben

RaffoPazzo

  • Community Member
  • Posts: 77
  • Hero Points: 2
Re: Attach to running process from command line
« Reply #1 on: February 15, 2013, 10:03:49 AM »
Have you seen debug_attach command? It takes an attach_info string parameter by which you can specify debugger's specific parameter like the PID and program path in your case.

rubenhak

  • Community Member
  • Posts: 6
  • Hero Points: 0
Re: Attach to running process from command line
« Reply #2 on: February 19, 2013, 09:40:41 PM »
Where is the debug_attach documented? could you point to an example?
I'm using the Slickedit v17.0.3 for Linux.

rubenhak

  • Community Member
  • Posts: 6
  • Hero Points: 0
Re: Attach to running process from command line
« Reply #3 on: February 21, 2013, 03:37:36 AM »
I tried the following but this doesnt seem to work.
sudo vs +new "-#debug_attach debugger_cb_name='gdb' attach_info='pid=28996,app=/my-project.bin'"

I get an error saying that "Attaching to a running process is not supported".  I believe that i'm not passing the arguments properly.

davehohl

  • Senior Community Member
  • Posts: 271
  • Hero Points: 27
Re: Attach to running process from command line
« Reply #4 on: February 21, 2013, 06:13:05 PM »
I'm not an expert on this, but since no one else has responded I figured I would give you my two cents.

I don't think you are supposed to include debugger_cb_name= and attach_info= in the call. I think those are just the names of the parameters for the function. I may be wrong on this, but at least it would be worth trying.

rubenhak

  • Community Member
  • Posts: 6
  • Hero Points: 0
Re: Attach to running process from command line
« Reply #5 on: February 21, 2013, 06:15:39 PM »
I tried without the names of the parameters but it still does not work :( is there some guide which. Describes how to invoke commands from cli?

davehohl

  • Senior Community Member
  • Posts: 271
  • Hero Points: 27
Re: Attach to running process from command line
« Reply #6 on: February 21, 2013, 06:40:34 PM »
The only thing I could find was by entering "command line" in the help/index tab. It appears that you have probably done that already since you have figured out the -# and the need to use quotes. Hopefully somebody more knowledgeable than me will see this thread an point you in the right direction. Sorry I can't be more help to you.

rubenhak

  • Community Member
  • Posts: 6
  • Hero Points: 0
Re: Attach to running process from command line
« Reply #7 on: February 21, 2013, 10:48:25 PM »
Tried various combinations but could not make it work.
These are the options i tried:
sudo vs +new "-#debug_attach debugger_cb_name='gdb' attach_info='pid=28996,app=/my-project.bin'"
sudo vs +new "-#debug_attach gdb pid=28996,app=/my-project.bin"
sudo vs +new "-#debug_attach 'gdb' 'pid=28996,app=/my-project.bin'"
sudo vs +new "-#debug_attach('gdb','pid=28996,app=/my-project.bin')"

Though I could create another macro and call the debug_attach from there and it worked. But i need to be able to run it from the command line.

RaffoPazzo

  • Community Member
  • Posts: 77
  • Hero Points: 2
Re: Attach to running process from command line
« Reply #8 on: February 22, 2013, 10:58:49 AM »
Probably you already did the right thing and simply attaching to a running process at the same time when launchin SE is not supported^^

Why you can't have SE already running and then attach to the running process ?

Dennis

  • Senior Community Member
  • Posts: 3961
  • Hero Points: 517
Re: Attach to running process from command line
« Reply #9 on: February 22, 2013, 03:04:46 PM »
When a Slick-C command is called from the command line, or from invocation, the string arguments are stuffed into the first argument to the function.  You will need a wrapper function to parse out the individual function arguments.  Try something as simple as this:

Code: [Select]
_command int debug_attach_gdb(_str attach_info="") name_info(','VSARG2_EDITORCTL|VSARG2_REQUIRES_MDI|VSARG2_READ_ONLY)
{
   return debug_attach("gdb", attach_info);
}

Then you will be able to invoke the editor with arguments like this:
Code: [Select]
vs +new "-#debug-attach-gdb pid=29914,app=/my-project.bin,session=GDB Attached"

I'm going to file a feature request to add smarter command line parsing to the debugger invocation commands.

rubenhak

  • Community Member
  • Posts: 6
  • Hero Points: 0
Re: Attach to running process from command line
« Reply #10 on: February 25, 2013, 06:44:20 PM »
Thank you Dennis. If first didn't accept my parameter from command line, but then i replaced it with -r option and it worked.

Just one thing. This works only when i run from the local user. But if i want to start the slickedit as a super user it fails to find and execute my command. I basically run like:
sudo vs +new -r debugattachgdb pid=1234,app=/my-project.bin,session=GDB Attached

Thanks,
Ruben