Sublime Forum

Debuging

#1

Hello,
is there a way to add some kind of debuging plugin maybe? To be able to add breakpoints and see local vars will be 70% of what i need @ the moment.
At the moment i 'm interested in GDB integration since this is what is used by go(lang)
Please let me know

0 Likes

#2

github.com/quarnster/SublimeGDB

0 Likes

#3

this is reaaaal good. Thank you!

a few hopefully queick questions and observations:
a. when i start the debugger (f5), right click on the variable -> “add to watches” the sublime hangs ofr a few seconds. I have 3 core AMD and it goes for 4% utilization ( nothing else is running ).
b. sorry about this naive question.
what is the right sequence for debugging session? Right now i’m doing this:

  1. save file.
  2. set breakpoint
  3. right click on the var to add it to the watch.
  4. F5 to start the debugger and F5 to advance to the breakpoint.

but i don’t see any indication of the degugger running, nor i see where the current line is …
Obviously i’m doing something wrong.
Please advise.

0 Likes

#4

Which OS are you using? The plugin is pretty much untested on Windows and has issues on Linux, making it impossible to add breakpoints or watches while the target is running. Feel free to contribute code fixing it.

As for running status, you’ll want to check the callstack view and the threads view. To fix anything that’s broken, you’ll likely want to keep an eye in the GDB Session view which will print all the commands sent to gdb and all the data that is received from it in raw format.

0 Likes

#5

[quote=“quarnster”]Which OS are you using? The plugin is pretty much untested on Windows and has issues on Linux, making it impossible to add breakpoints or watches while the target is running. Feel free to contribute code fixing it.
[/quote]

i’m on RH6 64. The link does not point to the issue i experienced - in my case the sublime is getting frozen for a few seconds while no execution/debugging is happening. It’s rather minor @ this point for me.

[quote] …
As for running status, you’ll want to check the callstack view and the threads view. To fix anything that’s broken, you’ll likely want to keep an eye in the GDB Session view which will print all the commands sent to gdb and all the data that is received from it in raw format.[/quote]

right - but do i do this right - set breakpoint, hit F5 and hit F5 again to get the program to advance to the breakpoint? becasue i see no changes anywhere. And it’s a simple code really:

package main

import (
//
“example/newmath”
“fmt”
“os”
)

type F_error struct {
f_name string
}

var (
F_name1 string = “/tmp/abc.txt”
F_name2 string
)

func main() {

// Open a file.
// Read from the file and print on to the screen
file_1, err := os.Open(F_name1)
if err != nil {
	fmt.Println(err)
}

fmt.Println("File name is %v ", &file_1)
// Read from another file and append original
// and replace the original file

fmt.Printf("Hello, world.  Sqrt(2) = %v\n", newmath.Sqrt(2))
// os.Open(new_file)

}

0 Likes

#6

Never done anything go releated. Check the GDB session view for info on what it’s doing.

0 Likes

#7

ok. it seems it’s waiting for “file” … hmmm
another question:
one closed (with mouse) all the “little” windows - stack etc. But the area where there were is still open. How can i close it if restart doesn’t help ?

0 Likes

#8

If it’s waiting for “file” you probably haven’t set sublimegdb_commandline properly in the configuration so it doesn’t know what executable you are trying to debug.

The layout is restored when the gdb session exits (select stop debugging in the right click menu). If stopping debugging doesn’t work, you can also use the layout shortcuts or menu item. Menu item View->Layout->Single for example.

0 Likes

#9

[quote=“quarnster”]If it’s waiting for “file” you probably haven’t set sublimegdb_commandline properly in the configuration so it doesn’t know what executable you are trying to debug.
[/quote]

correct you are . I haven’t touched anything. now i opened the sublimegdb.sublime-settings and it has this :

 // All options in here can also be specified in your project settings
    // with a prepended "sublimegdb_". You probably want to
    // have something like this in your project settings:
    //
    // "settings":
    // {
    //      "sublimegdb_sourcedir": "/path/to/your/project/source",
    //      "sublimegdb_workingdir": "/path/to/your/project",
    //      // NOTE: You MUST provide --interpreter=mi for the plugin to work
    //      "sublimegdb_commandline": "gdb --interpreter=mi ./your_executable_name"
*    //      ]
    // }
    //
    "workingdir": "/tmp",

    // NOTE: You MUST provide --interpreter=mi for the plugin to work
    "commandline": "gdb --interpreter=mi ./executable",

can i have the executable_name as a dynamic value? for example if i need to review the package it will have a different name from the main exec file.
i added “*” in one of the lines above. I believe there should be a “}” not a “]”.

how do i find out where the gdb gets executed? it seemed to unable to locate my file… – aha! i must have the sublimegdb_workingdi set.

[quote]
The layout is restored when the gdb session exits (select stop debugging in the right click menu). If stopping debugging doesn’t work, you can also use the layout shortcuts or menu item. Menu item View->Layout->Single for example.[/quote]

perfect - that worked like a charm. thank you !

now , once i added the sction above to the project file the gdb seemed to pick up on the file. At least i see some meaningful information.
here is what i noticed tho in gdb session window:

/usr/local/go/src/pkg/runtime/runtime-gdb.py (referenced in .debug_gdb_scripts): No such file or directory\n"
(gdb)
(gdb)
33^error,msg="Undefined show command: \"interpreter\".  Try \"help show\"."
(gdb)

i can’t locate the .debug_gdb_scripts file. where is it and is it important? — this is something GO specific. I’m looking into this. please ignore.
update: there is a http://code.google.com/p/go/issues/detail?id=3180

do i need to care about the “interpreter” error ?

i replaced the code above with the simple loop:

for i := 0; i < 10; i++ {
		println(i)
	}

put the breakpoint @ println line
now in gdb console i see the println (i’m assuming) printing the sequence of 0123… but how can i see the actual value in variable?
the gdb variables window is empty.
the gdb breakpoints has this :

-1 - watch: F_name1
-1 - watch: file_1
-1 - watch: i
1 - /home/azz/work/workspace/src/az/main.go:35

and in the gdb Session ( once i add the i thru the gdb drop down manu “Add watch”:

225-break-watch i
225^error,msg="No symbol \"i\" in current context."
(gdb)
0 Likes

#10

[quote=“dbabo”]…
now , once i added the section above to the project file the gdb seemed to pick up on the file. At least i see some meaningful information.
here is what i noticed tho in gdb session window:

/usr/local/go/src/pkg/runtime/runtime-gdb.py (referenced in .debug_gdb_scripts): No such file or directory\n"
(gdb)
(gdb)
33^error,msg="Undefined show command: \"interpreter\".  Try \"help show\"."
(gdb)

i can’t locate the .debug_gdb_scripts file. where is it and is it important? — this is something GO specific. I’m looking into this. please ignore.
update: there is a http://code.google.com/p/go/issues/detail?id=3180

do i need to care about the “interpreter” error ?

i replaced the code above with the simple loop:

for i := 0; i < 10; i++ {
		println(i)
	}

put the breakpoint @ println line
now in gdb console i see the println (i’m assuming) printing the sequence of 0123… but how can i see the actual value in variable?
the gdb variables window is empty.
the gdb breakpoints has this :

-1 - watch: F_name1
-1 - watch: file_1
-1 - watch: i
1 - /home/azz/work/workspace/src/az/main.go:35

and in the gdb Session ( once i add the i thru the gdb drop down manu “Add watch”:

[code]
225-break-watch i
225^error,msg=“No symbol “i” in current context.”
(gdb)

[/code][/quote]

I think the error “no symbol” is specific to GO. According to this manual GO vars are “package.var” (golang.org/doc/gdb).
This guy seemed to got GDB to play nicer %) with his IDE (code.google.com/p/liteide/) at least i can see all variables in the “variable” window during debugging.

I really wish i’m missing something obvious since over 2 days i’ve been playing with your extension and Sublime i found myself enjoying it much better then other implementations.

0 Likes

#11

I made some small tweaks in the plugin and was able to set a watch for i now. This should also list variables in the variables view where possible. The file_1 variable refused to show up for some reason though. Try updating the plugin to the latest code and see if that works better for you.

The “No symbol … in current context.” usually means that you are trying to set a watch where the variable isn’t defined. To watch i you have to set a breakpoint on the print statement and once that breakpoint is hit, you can add a watch for i.

0 Likes

#12

[quote=“quarnster”]I made some small tweaks in the plugin and was able to set a watch for i now. This should also list variables in the variables view where possible. The file_1 variable refused to show up for some reason though. Try updating the plugin to the latest code and see if that works better for you.

The “No symbol … in current context.” usually means that you are trying to set a watch where the variable isn’t defined. To watch i you have to set a breakpoint on the print statement and once that breakpoint is hit, you can add a watch for i.[/quote]

Awesome! Let me try right now…

BTW. I saw in your comments that you were not able to figure out how to set a new breakpoint while debugging. The author of LiteIde got it to work - i just tested it. So you may want to contact him.

0 Likes

#13

[quote=“quarnster”]I made some small tweaks in the plugin and was able to set a watch for i now. This should also list variables in the variables view where possible. The file_1 variable refused to show up for some reason though. Try updating the plugin to the latest code and see if that works better for you.

The “No symbol … in current context.” usually means that you are trying to set a watch where the variable isn’t defined. To watch i you have to set a breakpoint on the print statement and once that breakpoint is hit, you can add a watch for i.[/quote]

good news indeed!
i could see “i” now.
now i made a change to the code - in the loop i print the const ( F_name1).
But i can’t see it in the variables window.

Also - how can i remove the var from the watch window?


func main() {

	file_1, err := os.Open(F_name1)
	if err != nil {
		fmt.Println(err)
	}
	for i := 0; i < 10; i++ {
		println(i)
		println(F_name1)

	}

}
0 Likes

#14

Remove by pressing F9 with the cursor on the line in the breakpoint/watch window.

0 Likes

#15

cool. how about the F_name1 problem?

0 Likes

#16

Like I said earlier:

If it’s not listed, it wasn’t possible to create a gdb variable for it. Feel free to submit a pull request when you figure out what needs to be changed.

0 Likes

#17

[quote=“quarnster”]

Like I said earlier:

If it’s not listed, it wasn’t possible to create a gdb variable for it. Feel free to submit a pull request when you figure out what needs to be changed.[/quote]

i don’t know why but i can’t fish the value of constant from gdb.
quamster - thank you for the earlier fix. Life is good now :smile:

0 Likes