douyan4900 2014-05-30 10:55
浏览 76
已采纳

狂欢调试-如何[关闭]

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.

  • 写回答

1条回答 默认 最新

  • dongqiao9015 2014-05-30 12:18
    关注

    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 !

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开