Shop OBEX P1 Docs P2 Docs Learn Events
GDB over serial ready or coming? — Parallax Forums

GDB over serial ready or coming?

RaymanRayman Posts: 14,665
edited 2013-04-07 05:28 in Propeller 1
Was reading a bit about GDB (GNU debugger) and also WinGDB.

WinGDB should allow me to use GDB inside of Visual Studio over serial connection.
The price isn't so bad and there's also a free version (although limited).

Is GDB over serial connection something that is being developed?
Is it already available?
«1

Comments

  • ersmithersmith Posts: 6,054
    edited 2013-03-31 14:24
    It's in the p2test branch, so if you're using that version of PropGCC you can give it a try. No IDE integration is available yet, you'll have to use a command line.To use it, follow these steps:

    (1) Compile your program with -g and (preferably) with minimal optimization. In theory you can debug optimized programs, but the optimizer moves code around, and it can get very confusing. The debugger in theory works in LMM, CMM, and XMM modes, but XMM is extremely restricted because only 2 breakpoints are available (the debugger can't write into flash or EEPROM, and has to rely on a small table of breakpoints).

    (2) Run propeller-load with -g and -r, and without -t, to load the program and get it ready for debugging.

    (3) Launch propeller-elf-gdb, set any breakpoints you want, and then type "c" (for continue). ^C will often work to break the program, but isn't 100% reliable (if the program is stuck in a loop outside of the LMM interpreter it can't be interrupted).

    Here's a sample program:
    #include <stdio.h>
    
    void main() {
        printf("hello, world!\n");
        printf("goodbye, world!\n");
    }
    

    And here's a compile and debug session with it (I'm using Linux, but Windows would be the same except for the prompt):
    $ propeller-elf-gcc -g -o hello.elf hello.c
    $ propeller-load -bc3 hello.elf -r -g
    Propeller Version 1 on /dev/ttyUSB0
    patching for debug at offset 0x68
    Loading hello.elf to hub memory
    6516 bytes sent                  
    Verifying RAM ... OK
    $ propeller-elf-gdb hello.elf
    GNU gdb (GDB) 7.3.1
    Copyright (C) 2011 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=propeller-elf".
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>...
    0x000005b0 in ?? ()
    Reading symbols from /tmp/hello.elf...done.
    (gdb) break main
    Breakpoint 1 at 0x674: file hello.c, line 4.
    (gdb) c
    Continuing.
    
    Breakpoint 1, main () at hello.c:4
    4        printf("hello, world!\n");
    (gdb) next
    
    Breakpoint 1, main () at hello.c:4
    4        printf("hello, world!\n");
    (gdb) next
    hello, world!
    5        printf("goodbye, world!\n");
    (gdb) next
    goodbye, world!
    6    }
    (gdb)
    

    Eric
  • RaymanRayman Posts: 14,665
    edited 2013-03-31 17:10
    That looks great.
    Not sure I can make this work with WinGDB though...
    WinGDB talks about serial debugging, but it seems what the really mean is debugging using an OpenOCD JTAG interface.
  • Heater.Heater. Posts: 21,230
    edited 2013-03-31 21:02
    Get yourself onto a Unix/Linux machine and try out DDD. http://www.gnu.org/software/ddd/
  • SRLMSRLM Posts: 5,045
    edited 2013-03-31 21:49
    ersmith wrote: »
    It's in the p2test branch, so if you're using that version of PropGCC you can give it a try.
    ...
    (3) Launch propeller-elf-gdb, ...

    Hmmm. I just tried to run it, and it didn't install with my version of p2test build. It's not in /opt/parallax/bin:
    >>>$ ls /opt/parallax/bin/
    bstc.linux               propeller-elf-c++filt  propeller-elf-gcc-4.6.1   propeller-elf-ld.bfd   propeller-elf-readelf  spin2cpp
    propeller-elf-addr2line  propeller-elf-cpp      propeller-elf-gcov        propeller-elf-nm       propeller-elf-size
    propeller-elf-ar         propeller-elf-elfedit  propeller-elf-gprof       propeller-elf-objcopy  propeller-elf-strings
    propeller-elf-as         propeller-elf-g++      propeller-elf-image-size  propeller-elf-objdump  propeller-elf-strip
    propeller-elf-c++        propeller-elf-gcc      propeller-elf-ld          propeller-elf-ranlib   propeller-load
    

    My version:
    propeller-elf-gcc (propellergcc_v0_3_5_1943) 4.6.1
    

    And, it doesn't choke when I pass it -mp2 as an option, so I assume that I have the correct branch installed. What should I try next?
  • SRLMSRLM Posts: 5,045
    edited 2013-03-31 22:40
    Ok, I got it now. I pulled and rebuilt. I don't know why it wasn't there before.
    propeller-elf-g++ (propellergcc_v0_3_5_1958) 4.6.1
    
  • jazzedjazzed Posts: 11,803
    edited 2013-03-31 22:46
    SRLM wrote: »
    ...
    What should I try next?

    Make sure you have no changes in your tree. Then in propgcc ....
    $ hg pull
    $ hg update p2test
    $ ./jbuild.sh 6 rm-all

    I've been stepping through some CMM and LMM P1 code tonight with SimpleIDE (don't tell Parallax I was goofing around LOL).

    I need a way to distinguish debug info from console info. Any ideas? Wish there was a marker for all lines of gdb output.
  • Heater.Heater. Posts: 21,230
    edited 2013-04-01 01:46
    Jazzed,

    Are you sneaking a GDB interface into SimpleIDE?

    I just pulled and built propside again, it's looking very good.

    Being a sick human being I loaded it up with some JavaScript!

    Well, JS has a C like syntax so that looks pretty good as well. Starts me thinking, could I hack propside to do a better job of JS highlighting? Could it highlight matching brackets and braces (There tends to be rather more of those in JS)? Could I get it to run jslint and jump to lines with errors like it does with gcc error output? Could I get it to run the JavaScript by starting up node.js? could I get the node.js ouput into the serial terminal window? .....

    Am I sick?

    I think not. One thing I want to do is explore systems that are basically Propeller -> serial link -> webserver -> browser. Where the serial and web server are done in JavaScript running under node.js. In that kind of set up we need to develop C/C++ for the Prop and JavaScript for the server and browser client side. Would be neat to do it all in one IDE. SimpleIDE:)

    Excuse me whilst I start butchering your code....
  • SRLMSRLM Posts: 5,045
    edited 2013-04-01 02:17
    ersmith wrote: »
    (2) Run propeller-load with -g, and without -r, to load the program and get it ready for debugging.

    I had to run it as follows:
    propeller-load -g -r main.elf
    

    I also notice that this error message seems out of date for propeller-load:
    error: must specify -e, -r, or -s when an image file is specified
    

    When I run it with the same program, then I get the following when I set "break main":
    (gdb) break main
    warning: Can not parse XML memory map; XML support was disabled at compile time
    Breakpoint 1 at 0x674: file gdbtest.cpp, line 4.
    (gdb) c
    Continuing.
    

    From the link below, it looks like the expat-dev library needs to be installed. Once intalled it fixed that problem. Of the unmentioned dependencies, it looks like the total is (that I've run across) are: bison, libncurses-dev, and expat-dev

    http://stackoverflow.com/questions/5665800/compiling-gdb-for-remote-debugging

    One thing that would be helpful in this area is a "unified" gdb that takes care of downloading. It would make it easier to integrate into IDE's, I think.
  • ersmithersmith Posts: 6,054
    edited 2013-04-01 04:47
    Rayman wrote: »
    That looks great.
    Not sure I can make this work with WinGDB though...
    WinGDB talks about serial debugging, but it seems what the really mean is debugging using an OpenOCD JTAG interface.

    It probably can be made to work; WinGDB itself shouldn't care how gdb is talking to the target. But I don't know exactly how WinGDB works, so I don't know how much effort it would be to get this going.

    Eric
  • ersmithersmith Posts: 6,054
    edited 2013-04-01 04:52
    SRLM wrote: »
    I had to run it as follows:
    propeller-load -g -r main.elf
    
    Sorry, I messed up the original description -- you do need -r (as you discovered), it's -t that must be left out.
    One thing that would be helpful in this area is a "unified" gdb that takes care of downloading. It would make it easier to integrate into IDE's, I think.

    It's possible to build propeller-elf-gdb so that it can load P1 LMM files. But when I looked into extending this, there were a huge number of cases to support (P1 and P2 are different, and each has LMM and XMM with all the possible board configurations). I didn't like the idea of duplicating that much code between propeller-load and propeller-elf-gdb :-(. Sometime maybe we can come up with a shared library for both tools, but for now I think IDEs should be able to automate loading with propeller-load before running gdb; or we could write a small batch file/shell script to do this.

    Eric
  • RaymanRayman Posts: 14,665
    edited 2013-04-01 06:13
    I get an error when I try to run propeller-elf-gdb:

    "The procedure entry point libintl_setlocale could not be located in the dynamic link library libintl-8.dll"

    Thought maybe my GIMP install was messing it up, but that's not it.
    It is finding the libintl-8.dll in propgcc folder...
  • jazzedjazzed Posts: 11,803
    edited 2013-04-01 08:31
    Rayman I had to add the libintl-8.dll for the simpleide package. Didn't realize it was a gdb dependency too. Maybe David can post a pointer to the .dll from his mingw package.

    The problem I had with gdb was that the .gdbinit file is not in my path. I had to add "target remote | gdbstub -p <port>".


    Heater,

    The gdb stepping support has been in SimpleIDE for a while, but I didn't keep up with Eric's load method change. I don't expect it to be a fully developed feature for a while.

    I assume you remember that "hg update spinside" gets the latest version. Once this stage of SimpleIDE is done, spinside will be rolled into the default branch.

    Since you're looking at language stuff, I guess you've seen the builder class by now. That encapsulates lots of language specific build stuff, but there is still substantial cruft in the language selection. That cruft is the main barrier to adding new languages at the moment. I'd like to add an "other build" method that could be used for doing make or some other build.

    BTW, your javascript idea is not totally crazy. I'm interested in the possibility of web based gui of sorts, but there are so many security concerns with direct system access. I looked at that briefly over the last few weeks. One fellow created a client side plug-in called "seriality" https://code.google.com/p/seriality/ .... I haven't looked at it too deep. There are several Arduino related Javascript projects.

    Thinking about security and ease of use, it seems like having a "local" web server that runs PHP would be a fair solution, but as in anything else with direct system access, that would require some installation and configs.
  • Heater.Heater. Posts: 21,230
    edited 2013-04-01 10:46
    Yes I have the "spinside" branch here.

    To be honest, no, I have not looked so hard as to see the "builder class" yet.

    I can see a little problem with my plan, one would have to have a C/C++ project
    open for the Propeller stuff but at the same time be editing a JS project for
    the server side things.

    As for security and WEB access, "having a "local" web server that runs
    PHP" is no more secure than having a web server in node.js and server side
    scripts in JavaScript. Just a different language.

    Thing is you don't need to install Apache or nginx or whatever web server. Just run your 100 lines of JavaScript under node.js. Bingo! you have a web server, https, and a serial link to your Propeller.

    I have been meaning to post a description of such a set up for a while now.
  • jazzedjazzed Posts: 11,803
    edited 2013-04-01 10:56
    Heater. wrote: »
    As for security and WEB access, "having a "local" web server that runs
    PHP" is no more secure than having a web server in node.js and server side
    scripts in JavaScript. Just a different language.

    Hmm. I guess I misunderstood about JavaScript having any server side ability - I thought it was all client. That makes sense though since AJAX uses the network interface.

    I look forward to your description.

    Thanks.
  • Heater.Heater. Posts: 21,230
    edited 2013-04-01 11:17
    Ah, here is the thing, Google has a super fast JavaScript engine called V8. A young guy, Ryan Dahl, has adopted that to create node.js. Basically server side JavaScript. Well, it means you can use JS as you would Python or Perl on the command line. But he has tuned it for networking stuff.

    So there you have a super simple way to create a WEB server. Like 10 lines of code.

    But then:

    1) Forget all that AJAX stuff. With node.js we can do HTML 5 websockets really easily. So we have a hot line between server and browser.
    2) Node.js has already thousands of add on modules, which include serial communication.

    Bingo, we have a hot line from Propeller to browser.

    Check this out:

    http://nodejs.org/

    http://www.youtube.com/watch?v=jo_B4LTHi3I

    http://socket.io/
  • RaymanRayman Posts: 14,665
    edited 2013-04-01 11:53
    The error I'm getting seems to indicate that it finds libintl-8.dll just fine, but the dll does not contain the setlocale function...
  • RaymanRayman Posts: 14,665
    edited 2013-04-02 08:15
    Ok, I think I have the library problem fixed...

    David suggested installing MinGW. That didn't fix it, but I did find a different version of libintl-8.dll in the bin folder there.
    That one first complained about not having libgcc_s_dw2-1.dll installed, so I had to copy that file over too.

    Now, it seems to work.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-04-02 08:29
    Rayman wrote: »
    Ok, I think I have the library problem fixed...

    David suggested installing MinGW. That didn't fix it, but I did find a different version of libintl-8.dll in the bin folder there.
    That one first complained about not having libgcc_s_dw2-1.dll installed, so I had to copy that file over too.

    Now, it seems to work.
    I guess that means that I should add those two libraries to the standard PropGCC Windows release. Thanks for tracking that down!
  • RaymanRayman Posts: 14,665
    edited 2013-04-02 08:32
    I'm pretty happy about having gdb. I may explore WinGDB too, but I think it's not a solution for everybody, because you can't use it with the free version
    of Visual Studio.

    Still, I can now have a real debug and release mode working in free version of Visual Studio.
    Running GDB in terminal mode is going to take some learning, but it's a whole lot better than nothing.

    If this debugging can be added in a more integrated way to other free IDE's like
    SimpleIDE, CodeBlocks or Eclipse, they will have a big advantage over me in Visual Studio...
    (But, I'll stick with it anyway!)
  • RaymanRayman Posts: 14,665
    edited 2013-04-04 19:15
    Heard back from WinGDB support today... They think it should work, here's the reply:

    Hello,

    Possibly yes, depending on what command is needed to connect GDB
    to underlying debugger interface. Typically it is some variant of
    "target" command (e.g. "target remote 127.0.0.1:<port>"). If you
    enter such command in 'propeller-elf-gdb' then it should work
    with WinGDB also. Use Embedded Device mode and enter arguments for
    'target' command in "Target specification" field, e.g. "remote 127.0.0.1:<port>".



    Best regards,
    Przemek Kuczmierczyk
    WinGDB.com
    WinGDB Support,

    Parallax is finishing up a GCC port for their Propeller microcontrollers...
    I was looking into using WinGDB with Visual Studio to debugging, but it's not clear it can work...
    They are not using a JTAG device, but just a simple USB serial connection over a Windows COM port.
    This is how they are set up to debug at the command line:

    propeller-elf-gcc -g -o hello.elf hello.c
    propeller-load -bc3 hello.elf -r -g
    propeller-elf-gdb hello.elf

    propeller-elf-gdb then shows a terminal window where the debugging commands can be entered...
    Think there's any chance of this working with WinGDB?

    Thanks,
    Ray
  • ersmithersmith Posts: 6,054
    edited 2013-04-05 04:15
    The gdb command to connect to the propeller is
    target remote |gdbstub
    
    We've put that command into the system gdbinit file (in $PARALLAX/lib/gdb/gdbinit) so it should be executed automatically for you when propeller-elf-gdb starts up. It probably won't hurt for it to run again, although you may see a warning from gdb.

    Eric
  • jazzedjazzed Posts: 11,803
    edited 2013-04-05 07:07
    ersmith wrote: »
    We've put that command into the system gdbinit file (in $PARALLAX/lib/gdb/gdbinit) so it should be executed automatically for you when propeller-elf-gdb starts up. It probably won't hurt for it to run again, although you may see a warning from gdb.

    That doesn't work for SimpleIDE. I have to enter the command in the startup code. Maybe gdbinit would be found if I put it in the propeller-gcc bin ?
  • ersmithersmith Posts: 6,054
    edited 2013-04-05 07:49
    jazzed wrote: »
    That doesn't work for SimpleIDE. I have to enter the command in the startup code. Maybe gdbinit would be found if I put it in the propeller-gcc bin ?

    Hmmm, that's odd. It's supposed to look for it in $PATH_TO_GDB_PROGRAM/../lib/gdb/gdbinit. Perhaps for some reason argv[0] isn't being set correctly in propeller-elf-gdb. I'm not sure how the runtime picks this up, but perhaps it depends on how you invoke gdb?

    Some other alternatives are:

    (1) Put a .gdbinit in the $HOME directory (not sure if this will always be set in Windows);
    (2) Pass "-x /full/path/to/gdbinit" on the command line when you start propeller-elf-gdb.

    Eric
  • RaymanRayman Posts: 14,665
    edited 2013-04-06 04:36
    Made a little progress (I think) with WinGDB... But, I'm on a different computer now and GDB doesn't want to work right for some reason...
    I repeated the simple example above and everything seems OK until I enter "c" for continue.

    The response is "The program is not being run.".

    I'll have to try on another computer. Maybe somehow I installed something here that messed it up...
  • ersmithersmith Posts: 6,054
    edited 2013-04-06 04:42
    Rayman wrote: »
    Made a little progress (I think) with WinGDB... But, I'm on a different computer now and GDB doesn't want to work right for some reason...
    I repeated the simple example above and everything seems OK until I enter "c" for continue.

    The response is "The program is not being run.".
    Do you have the p2test version of PropGCC installed on both computers? gdb requires that version to work.

    Eric
  • RaymanRayman Posts: 14,665
    edited 2013-04-06 05:52
    I copied over the whole propgcc folder from the computer that I think was working...

    Trying on another PC now... This one gives same message but may have the 26Feb version on it. I'll try again with the 19Mar version...
  • David BetzDavid Betz Posts: 14,516
    edited 2013-04-06 06:05
    Rayman wrote: »
    I copied over the whole propgcc folder from the computer that I think was working...

    Trying on another PC now... This one gives same message but may have the 26Feb version on it. I'll try again with the 19Mar version...
    I'm about to upload a new p2test version so you may want to wait for that. It should be there in an hour or so.
  • RaymanRayman Posts: 14,665
    edited 2013-04-06 06:19
    Great. 'cause I'm starting to think it never was working... Maybe I stopped after seeing the program running and never tried "c"...
  • David BetzDavid Betz Posts: 14,516
    edited 2013-04-06 06:30
    Rayman wrote: »
    Great. 'cause I'm starting to think it never was working... Maybe I stopped after seeing the program running and never tried "c"...
    The new version dated 2013-04-06 is up on Google Code now.
  • jazzedjazzed Posts: 11,803
    edited 2013-04-06 07:33
    >> The response is "The program is not being run.".

    You must r before you can c.

    In other words, set a breakpoint on main, run, wait for (gdb) prompt, then continue.

    $ b main
    $ r
    (gdb) main() ...
    $ c
Sign In or Register to comment.