Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revel debugging - How to [closed]

Tags:

go

revel

Can some one provide some guidance about how to debug a Revel application. I might be dumb but I can't manage to do it. Some clear steps would be of real help.

like image 412
Mihai H Avatar asked Jan 10 '23 12:01

Mihai H


1 Answers

Revel is simply a set of libraries on top of the standard Go libraries, plus some wrappers creating a nice structure for you.

You can debug it like any other go applications using GDB.

More specifically, you can build it first and then debug the corresponding executable (this assumes my GOPATH is ~/workspace):

[user@host ~]$ workspace/bin/revel new app
~
~ revel! http://revel.github.io
~
Your application is ready:
    /home/user/workspace/src/app

You can run it with:
   revel run app
[user@host ~]$ workspace/bin/revel build app app
~
~ revel! http://revel.github.io
~
INFO  2014/05/30 12:21:25 revel.go:320: Loaded module static
TRACE 2014/05/30 12:21:25 build.go:128: Exec: [/usr/bin/git --git-dir=/home/user/workspace/src/app/.git describe --always --dirty]
WARN  2014/05/30 12:21:25 build.go:132: Cannot determine git repository version: exit status 128
TRACE 2014/05/30 12:21:25 build.go:77: Exec: [/home/user/go/bin/go build -ldflags -X app/app.APP_VERSION "" -tags  -o /home/user/workspace/bin/app app/app/tmp]

You then have an self-contained executable app at /home/user/workspace/bin/app, which you can run independently from revel like so (note that cmd line arguments are mandatory, otherwise the program will crash):

[user@host ~]$ workspace/bin/app -importPath app revel -srcPath "workspace/src" -runMode dev
INFO  2014/05/30 12:51:40 revel.go:320: Loaded module static
INFO  2014/05/30 12:51:40 revel.go:320: Loaded module testrunner
INFO  2014/05/30 12:51:40 main.go:26: Running revel server
Listening on :9000...

You can then debug this executable using GDB as you would do any other program:

[user@host ~]$ gdb -silent --args workspace/bin/app -importPath app revel -srcPath "workspace/src" -runMode dev
Reading symbols from workspace/bin/app...done.
Loading Go Runtime support.

Then using the GDB commands to start the program and set breakpoints:

(gdb) start
Temporary breakpoint 1 at 0x400c00: file /home/user/workspace/src/app/app/tmp/main.go, line 23.
Starting program: /home/user/workspace/bin/app -importPath app revel -srcPath workspace/src -runMode dev
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7fffe7804700 (LWP 5742)]

Temporary breakpoint 1, main.main () at /home/user/workspace/src/app/app/tmp/main.go:23
23      func main() {
(gdb) b workspace/src/app/app/controllers/app.go:9
Breakpoint 2 at 0x465610: file /home/user/workspace/src/app/app/controllers/app.go, line 9.
(gdb) cont
Continuing.
INFO  2014/05/30 13:12:31 revel.go:320: Loaded module static
INFO  2014/05/30 13:12:31 main.go:26: Running revel server
TRACE 2014/05/30 13:12:31 controller.go:375: Registered controller: App
TRACE 2014/05/30 13:12:31 controller.go:375: Registered controller: Static
TRACE 2014/05/30 13:12:31 watcher.go:94: Watching: /home/user/workspace/src/app/app/views
TRACE 2014/05/30 13:12:31 watcher.go:94: Watching: /home/user/workspace/src/app/app/views/App
TRACE 2014/05/30 13:12:31 watcher.go:94: Watching: /home/user/workspace/src/app/app/views/errors
TRACE 2014/05/30 13:12:31 watcher.go:94: Watching: /home/user/workspace/src/github.com/revel/revel/templates
TRACE 2014/05/30 13:12:31 watcher.go:94: Watching: /home/user/workspace/src/github.com/revel/revel/templates/errors
TRACE 2014/05/30 13:12:31 i18n.go:119: Successfully loaded messages from file sample.en
TRACE 2014/05/30 13:12:31 watcher.go:72: Watching: /home/user/workspace/src/app/conf/routes
[New Thread 0x7fffe6ea3700 (LWP 5743)]
[New Thread 0x7fffe66a2700 (LWP 5744)]
[New Thread 0x7fffe5ea1700 (LWP 5745)]
[New Thread 0x7fffe56a0700 (LWP 5746)]
Listening on :9000...

At this point, your program is running, but your controllers are not (yet) called: the code will only be executed when a query comes in, so go to your browser and access: "localhost:9000" (or whatever port you configured in app.conf) to trigger the response:

TRACE 2014/05/30 13:12:36 template.go:174: Refreshing templates from [/home/user/workspace/src/app/app/views /home/user/workspace/src/github.com/revel/revel/templates]
INFO  2014/05/30 13:12:36 router.go:293: Skipping routes for inactive module testrunner
TRACE 2014/05/30 13:12:36 i18n.go:183: Unable to read locale cookie with name 'REVEL_LANG': http: named cookie not present
TRACE 2014/05/30 13:12:36 i18n.go:149: Found Accept-Language header value: en-GB
[Switching to Thread 0x7fffe56a0700 (LWP 5746)]

Breakpoint 2, app/app/controllers.App.Index (c=..., ~anon0=...) at /home/user/workspace/src/app/app/controllers/app.go:9
9       func (c App) Index() revel.Result {
(gdb) 

And you are now at your breakpoint in your controller.

And then proceed using GDB. (There are plenty of interface to GDB, from command line (like CGDB) to graphical ones, or ones included in IDEs (like in GoClipse), but it all boils down to the same process eventually.

Good luck with your code !

like image 96
val Avatar answered Feb 28 '23 11:02

val