<bdo id='dlSns'></bdo><ul id='dlSns'></ul>
    <tfoot id='dlSns'></tfoot>
      <legend id='dlSns'><style id='dlSns'><dir id='dlSns'><q id='dlSns'></q></dir></style></legend>
    1. <small id='dlSns'></small><noframes id='dlSns'>

      <i id='dlSns'><tr id='dlSns'><dt id='dlSns'><q id='dlSns'><span id='dlSns'><b id='dlSns'><form id='dlSns'><ins id='dlSns'></ins><ul id='dlSns'></ul><sub id='dlSns'></sub></form><legend id='dlSns'></legend><bdo id='dlSns'><pre id='dlSns'><center id='dlSns'></center></pre></bdo></b><th id='dlSns'></th></span></q></dt></tr></i><div id='dlSns'><tfoot id='dlSns'></tfoot><dl id='dlSns'><fieldset id='dlSns'></fieldset></dl></div>

        如何使用 gdb 从核心文件中获取 lua 堆栈跟踪

        How can I get the lua stack trace from a core file using gdb(如何使用 gdb 从核心文件中获取 lua 堆栈跟踪)
          <bdo id='uu9vE'></bdo><ul id='uu9vE'></ul>

            1. <small id='uu9vE'></small><noframes id='uu9vE'>

                <tbody id='uu9vE'></tbody>

              <tfoot id='uu9vE'></tfoot>
                <legend id='uu9vE'><style id='uu9vE'><dir id='uu9vE'><q id='uu9vE'></q></dir></style></legend>
                <i id='uu9vE'><tr id='uu9vE'><dt id='uu9vE'><q id='uu9vE'><span id='uu9vE'><b id='uu9vE'><form id='uu9vE'><ins id='uu9vE'></ins><ul id='uu9vE'></ul><sub id='uu9vE'></sub></form><legend id='uu9vE'></legend><bdo id='uu9vE'><pre id='uu9vE'><center id='uu9vE'></center></pre></bdo></b><th id='uu9vE'></th></span></q></dt></tr></i><div id='uu9vE'><tfoot id='uu9vE'></tfoot><dl id='uu9vE'><fieldset id='uu9vE'></fieldset></dl></div>
                • 本文介绍了如何使用 gdb 从核心文件中获取 lua 堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 C++ 应用程序(用于 OS X),它调用 lua 作为脚本语言.我正在运行大量这些应用程序(100 个)并且它们可以运行很长一段时间(几天或几周).

                  I have a C++ application (for OS X) that calls lua as a scripting language. I'm running a large number of these applications (100s) and they can run for a very long time (days or weeks).

                  有时会崩溃.当它崩溃时,它给我留下了一个可爱的核心文件.

                  Sometimes one crashes. And when it crashes it leaves me a lovely core file.

                  我可以在 gdb 中打开这个核心文件并找到应用程序崩溃的地方.我可以遍历调用堆栈并找到一个 lua_State 变量的实例.我的问题是我想看看 lua 调用堆栈是什么样的这次……

                  I can open this core file in gdb and find where the application crashes. I can walk the call stack and find an instance of a lua_State variable. My problem is that I'd like to see what the lua call stack looks like at this time...

                  请记住,由于这是一个核心,我无权调用 C 函数,这排除了调试 lua 脚本的几种常用方法.

                  Keep in mind that since this is a core I don't have access to calling C functions, which rules out several of the usual ways of debugging lua scripts.

                  我希望避免通过调试挂钩添加手动跟踪,因为我担心额外的性能损失和增加的复杂性.

                  Id like to avoid adding manual traces through debug hooks as I'm worried about the additional performance penalties, and added complexity.

                  如何遍历lua内部结构来获取调用栈信息?

                  How can I traverse the lua internal structures to get at call stack information?

                  推荐答案

                  我已经创建了一个 GDB 脚本来执行由 macs 链接的网页中的内容.它并不漂亮,可能应该正确地包装成一个函数等,但这里是为了好奇.

                  I've created a GDB script to do the stuff in the web page linked to by macs. Its not beautiful, and should probably be properly wrapped into a function etc, but here it is for the curious.

                  注意:似乎网页关于 lua 函数的文件名是错误的.在字符串来自 luaL_dofile() 的情况下,文件名以 @ 符号开头.如果它们是从 lua_dostring() 调用的.在这种情况下,$filename 变量被设置为传递给 lua_dostring() 的整个字符串 - 用户可能只对其中的一两行上下文感兴趣那个文件.我不知道如何解决这个问题.

                  NOTE: It seems that the web page is wrong about the filename for lua functions. In the case where the string comes from luaL_dofile() the filename starts with a @ symbol. If they're called from lua_dostring(). In that case the $filename variable is set to the whole of the string passed to lua_dostring() - and the user is probably only interested in one or two lines of context from that file. I wasn't sure how to fix that up.

                  set $p = L->base_ci
                  while ($p <= L->ci )
                    if ( $p->func->value.gc->cl.c.isC == 1 )
                      printf "0x%x   C FUNCTION", $p
                      output $p->func->value.gc->cl.c.f
                      printf "
                  "
                    else
                      if ($p->func.tt==6)
                        set $proto = $p->func->value.gc->cl.l.p
                        set $filename = (char*)(&($proto->source->tsv) + 1)
                        set $lineno = $proto->lineinfo[ $p->savedpc - $proto->code -1 ]
                        printf "0x%x LUA FUNCTION : %d %s
                  ", $p, $lineno, $filename
                      else
                        printf "0x%x LUA BASE
                  ", $p
                      end
                    end
                    set $p = $p+1
                  end
                  

                  这输出类似:

                  0x1002b0 LUA BASE
                  0x1002c8 LUA FUNCTION : 4 @a.lua
                  0x1002e0 LUA FUNCTION : 3 @b.lua
                  0x100310   C FUNCTION(lua_CFunction) 0x1fda <crash_function(lua_State*)>
                  

                  当我通过这段代码调试崩溃时:

                  When I debug the crash from this code:

                  // This is a file designed to crash horribly when run.
                  // It should generate a core, and it should crash inside some lua functions
                  
                  #include "lua.h"
                  #include "lualib.h"
                  #include "lauxlib.h"
                  
                  #include <iostream>
                  #include <signal.h>
                  
                  int crash_function(lua_State * L)
                  {
                    raise( SIGABRT ); //This should dump core!
                    return 0;
                  }
                  
                  
                  
                  int main()
                  {
                    lua_State * L = luaL_newstate();
                    lua_pushcfunction(L, crash_function);
                    lua_setfield(L, LUA_GLOBALSINDEX, "C");
                  
                    luaopen_base(L);
                    if( 1 == luaL_dofile(L, "a.lua" ))
                    {
                      std::cout<<"ERROR: "<<lua_tostring(L,-1)<<std::endl;
                      return 1;
                    }
                    if( 1 == luaL_dofile(L, "b.lua" ))
                    {
                      std::cout<<"ERROR: "<<lua_tostring(L,-1)<<std::endl;
                      return 1;
                    }
                  
                    lua_getfield(L, LUA_GLOBALSINDEX, "A");
                    lua_pcall(L, 0, 0, NULL);
                  }
                  

                  使用a.lua

                  -- a.lua
                  -- just calls B, which calls C which should crash
                  function A()
                    B()
                  end
                  

                  和 b.lua

                  -- b.lua
                  function B()
                    C()
                  end
                  

                  这篇关于如何使用 gdb 从核心文件中获取 lua 堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)
                • <legend id='CDb3X'><style id='CDb3X'><dir id='CDb3X'><q id='CDb3X'></q></dir></style></legend>

                    <tbody id='CDb3X'></tbody>
                  <tfoot id='CDb3X'></tfoot>

                    • <bdo id='CDb3X'></bdo><ul id='CDb3X'></ul>
                          1. <small id='CDb3X'></small><noframes id='CDb3X'>

                            <i id='CDb3X'><tr id='CDb3X'><dt id='CDb3X'><q id='CDb3X'><span id='CDb3X'><b id='CDb3X'><form id='CDb3X'><ins id='CDb3X'></ins><ul id='CDb3X'></ul><sub id='CDb3X'></sub></form><legend id='CDb3X'></legend><bdo id='CDb3X'><pre id='CDb3X'><center id='CDb3X'></center></pre></bdo></b><th id='CDb3X'></th></span></q></dt></tr></i><div id='CDb3X'><tfoot id='CDb3X'></tfoot><dl id='CDb3X'><fieldset id='CDb3X'></fieldset></dl></div>