有些人可以就如何调试Revel应用程序提供一些指导。我可能会愚蠢,但我无法做到。一些明确的步骤将是真正的帮助。
答案 0 :(得分:9)
Revel只是一组基于标准Go库的库,还有一些包装器为你创建了一个很好的结构。
您可以像使用GDB的其他任何应用程序一样调试它。
更具体地说,您可以先构建它然后调试相应的可执行文件(假设我的GOPATH是〜/工作区):
[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]
然后你在/home/user/workspace/bin/app
有一个自包含的可执行应用程序,你可以像这样独立于revel运行(注意cmd行参数是必需的,否则程序会崩溃):
[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...
然后,您可以像使用任何其他程序一样使用GDB调试此可执行文件:
[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.
然后使用GDB命令启动程序并设置断点:
(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...
此时,您的程序正在运行,但您的控制器尚未被调用:代码将仅在查询进入时执行,因此请访问您的浏览器并访问:" localhost:9000&# 34; (或在app.conf中配置的任何端口)以触发响应:
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)
现在你正处于控制器的断点处。
然后继续使用GDB。 (GDB有很多接口,从命令行(如CGDB)到图形化接口,或IDE中包含的接口(如GoClipse),但最终归结为相同的过程。
祝你的代码好运!