Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6982849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:20:33+00:00 2026-05-27T18:20:33+00:00

I have a C++ application (for OS X) that calls lua as a scripting

  • 0

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.

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…

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.

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:20:33+00:00Added an answer on May 27, 2026 at 6:20 pm

    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.

    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 "\n"
      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\n", $p, $lineno, $filename
        else
          printf "0x%x LUA BASE\n", $p
        end
      end
      set $p = $p+1
    end
    

    This outputs something like:

    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);
    }
    

    With a.lua

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

    and b.lua

    -- b.lua
    function B()
      C()
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that calls a number stored by the user. Everything works
I have a Flex application that calls a function which searches a large document
I'm running Lighttpd on Cygwin. I have a Lua CGI script that calls a
I have a C# application that calls a stored procedure that produces an xml
I have created a console application that calls a method on a webservice. I
I have an ASP.NET application that calls other web services through SSL (outside the
I have a script that calls an application that requires user input, e.g. run
I have recently been working on a C# application that calls a webservice over
I have a .NET application that uses some API calls, for example GetPrivateProfileString .
We have built a web application that accepts SOAP messages, does some processing, calls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.