bmx-ng / brl.mod

BlitzMax Runtime Libraries, for BlitzMax NG.
12 stars 11 forks source link

x64 "DebugError: stack underflow" #12

Closed Octav14n closed 9 years ago

Octav14n commented 9 years ago

So now I can't start bmk compiled in 64 bit (Ubuntu 15.04, 64 bit, gcc version 4.9.2)

Steps to reproduce:

  1. compile bmk to linuxx64.
  2. start "bmk makemod -v -g x86" (even without arguments the error occurs.)

there is only the line DebugError: stack underflow on the screen, gdb says the following:

(gdb) r
Starting program: /home/octavian/Programmierung/bmax/bin/bmk makemod -v -g x86
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff62ea700 (LWP 1332)]
[New Thread 0x7ffff6aeb700 (LWP 1331)]
[New Thread 0x7ffff72ec700 (LWP 1330)]

Breakpoint 1, brl_appstub_debugger_mt_stdio_OnDebugLeaveScope ()
    at /home/octavian/Programmierung/bmax/mod/brl.mod/appstub.mod/.bmx/debugger_mt.stdio.bmx.debug.linux.x64.c:1183
1183            brl_appstub_debugger_mt_stdio_DebugError(&_s94);
(gdb) info local
bbt_dbgState = 0x7befc0
(gdb) print *bbt_dbgState
$1 = {clas = 0x6fb940 <brl_appstub_debugger_mt_stdio_TDbgState>, _brl_appstub_debugger_mt_stdio_tdbgstate_mode = 0, 
  _brl_appstub_debugger_mt_stdio_tdbgstate_debuglevel = 0, _brl_appstub_debugger_mt_stdio_tdbgstate_funclevel = 0, 
  _brl_appstub_debugger_mt_stdio_tdbgstate_currentscope = 0x80dc00, 
  _brl_appstub_debugger_mt_stdio_tdbgstate_scopestack = 0x7bfea0, 
  _brl_appstub_debugger_mt_stdio_tdbgstate_scopestacktop = 0, 
  _brl_appstub_debugger_mt_stdio_tdbgstate_exstatestack = 0x7bfd80, 
  _brl_appstub_debugger_mt_stdio_tdbgstate_exstatestacktop = 0}
(gdb) print _brl_appstub_debugger_mt_stdio_tdbgstate_currentscope
No symbol "_brl_appstub_debugger_mt_stdio_tdbgstate_currentscope" in current context.
(gdb) print *bbt_dbgState->_brl_appstub_debugger_mt_stdio_tdbgstate_currentscope
$3 = {clas = 0x6fb800 <brl_appstub_debugger_mt_stdio_TScope>, _brl_appstub_debugger_mt_stdio_tscope_scope = 0x0, 
  _brl_appstub_debugger_mt_stdio_tscope_inst = 0x0, _brl_appstub_debugger_mt_stdio_tscope_stm = 0x0}
(gdb) print *bbt_dbgState->_brl_appstub_debugger_mt_stdio_tdbgstate_scopestack
$4 = {clas = 0x7113c0 <bbArrayClass>, type = 0x4d64ad ":", dims = 1, size = 256, scales = {32}}
(gdb) print *bbt_dbgState->_brl_appstub_debugger_mt_stdio_tdbgstate_exstatestack
$5 = {clas = 0x7113c0 <bbArrayClass>, type = 0x4d64ad ":", dims = 1, size = 256, scales = {32}

It's the correspondig code to this .bmx lines:

Function OnDebugPopExState()

    Local dbgState:TDbgState = GetDbgState()
    GCSuspend

    If Not dbgState.exStateStackTop DebugError "exception stack underflow"

    dbgState.exStateStackTop:-1

    dbgState.scopeStackTop=dbgState.exStateStack[dbgState.exStateStackTop].scopeStackTop

    If dbgState.scopeStackTop
        dbgState.currentScope=dbgState.scopeStack[dbgState.scopeStackTop-1]
    Else
        dbgState.currentScope=New TScope
    EndIf

    GCResume    
End Function

this is the correspondig backtrace:

(gdb) bt
#0  brl_appstub_debugger_mt_stdio_OnDebugLeaveScope ()
    at /home/octavian/Programmierung/bmax/mod/brl.mod/appstub.mod/.bmx/debugger_mt.stdio.bmx.debug.linux.x64.c:1183
#1  0x000000000043e702 in __bmk_ng_TBMK_LoadBMK (o=0x7c3f80, bbt_path=0x820c80)
    at /home/octavian/Programmierung/bmax/src/bmk/.bmx/bmk_ng.bmx.debug.linux.x64.c:747
#2  0x000000000044b6df in _bmk_ng_LoadBMK (bbt_path=0x820c80)
    at /home/octavian/Programmierung/bmax/src/bmk/.bmx/bmk_ng.bmx.debug.linux.x64.c:5835
#3  0x000000000044bf14 in _bb_bmk_bmk_ng ()
    at /home/octavian/Programmierung/bmax/src/bmk/.bmx/bmk_ng.bmx.debug.linux.x64.c:6702
#4  0x000000000043c8dd in _bb_bmk_bmk_util ()
    at /home/octavian/Programmierung/bmax/src/bmk/.bmx/bmk_util.bmx.debug.linux.x64.c:4742
#5  0x0000000000431909 in _bb_bmk_bmk_modutil ()
    at /home/octavian/Programmierung/bmax/src/bmk/.bmx/bmk_modutil.bmx.debug.linux.x64.c:2958
#6  0x000000000042a8df in _bb_bmk_bmk_make ()
    at /home/octavian/Programmierung/bmax/src/bmk/.bmx/bmk_make.bmx.debug.linux.x64.c:4049
#7  0x000000000040b56f in _bb_main ()
    at /home/octavian/Programmierung/bmax/src/bmk/.bmx/bmk.bmx.console.debug.linux.x64.c:2319
#8  0x00000000004045fa in __bb_brl_appstub_appstub ()
    at /home/octavian/Programmierung/bmax/mod/brl.mod/appstub.mod/.bmx/appstub.bmx.debug.linux.x64.c:9
#9  0x00000000004044af in main (argc=5, argv=0x7fffffffdea8)
    at /home/octavian/Programmierung/bmax/mod/brl.mod/appstub.mod/appstub.linux.c:18

frame 1:

(gdb) frame 1
#1  0x000000000043e702 in __bmk_ng_TBMK_LoadBMK (o=0x7c3f80, bbt_path=0x820c80)
    at /home/octavian/Programmierung/bmax/src/bmk/.bmx/bmk_ng.bmx.debug.linux.x64.c:747
747                                     bbOnDebugLeaveScope();
(gdb) info local
bbt_e2 = 0x756b20
__scope = {kind = 5051198, name = 0x7fffffffd2e0 "0Lp", decls = {{kind = 0, name = 0x7befc0 "@\271o", 
      type_tag = 0x704c30 <_s61> "\300\025q", {
        const_value = 0x404afa <brl_appstub_debugger_mt_stdio_OnDebugLeaveScope+202>, field_offset = 4213498, 
        var_address = 0x404afa <brl_appstub_debugger_mt_stdio_OnDebugLeaveScope+202>}}, {kind = 7359536, 
      name = 0x7befc0 "@\271o", type_tag = 0x7c2d00 "\200@p", {
        const_value = 0x453fee <brl_maxlua_lua_registerobject+318>, field_offset = 4538350, 
        var_address = 0x453fee <brl_maxlua_lua_registerobject+318>}}}}
__stmt_0 = {source_file = 0x0, line_num = 0, char_num = 0}
ex = <optimized out>
buf = <optimized out>
bbt_e = 0x7ffff736ff90 <__GI___libc_malloc+96>
__scope = {kind = 5071712, name = 0x261 <error: Cannot access memory at address 0x261>, decls = {{kind = 1, 
      name = 0x4d620a "lua_setglobal", type_tag = 0x2 <error: Cannot access memory at address 0x2>, {
        const_value = 0x4d614e, field_offset = 5071182, var_address = 0x4d614e}}, {kind = 5088054, 
      name = 0x7fffffffd2e8 " ku", type_tag = 0x2 <error: Cannot access memory at address 0x2>, {const_value = 0x4d5410, 
        field_offset = 5067792, var_address = 0x4d5410}}}}
__stmt_0 = {source_file = 0x100000002 <error: Cannot access memory at address 0x100000002>, line_num = 348345088, 
  char_num = 1181975205}
ex = <optimized out>
buf = <optimized out>
bbt_str = 0x711580 <bbEmptyString>
bbt_pos = 0
---Type <return> to continue, or q <return> to quit---
bbt_inDefine = 0
bbt_text = 0x711580 <bbEmptyString>
bbt_name = 0x711580 <bbEmptyString>
__scope = {kind = 1, name = 0x4d5a56 "LoadBMK", decls = {{kind = 2, name = 0x4d5349 "path", type_tag = 0x4d133e "$", {
        const_value = 0x7fffffffce88, field_offset = 140737488342664, var_address = 0x7fffffffce88}}, {kind = 2, 
      name = 0x4d5584 "str", type_tag = 0x4d133e "$", {const_value = 0x7fffffffcea0, field_offset = 140737488342688, 
        var_address = 0x7fffffffcea0}}, {kind = 2, name = 0x4da9f9 "pos", type_tag = 0x4d15b3 "i", {
        const_value = 0x7fffffffce94, field_offset = 140737488342676, var_address = 0x7fffffffce94}}, {kind = 2, 
      name = 0x4d53f4 "inDefine", type_tag = 0x4d15b3 "i", {const_value = 0x7fffffffce98, 
        field_offset = 140737488342680, var_address = 0x7fffffffce98}}, {kind = 2, name = 0x4d5404 "text", 
      type_tag = 0x4d133e "$", {const_value = 0x7fffffffcea8, field_offset = 140737488342696, 
        var_address = 0x7fffffffcea8}}, {kind = 2, name = 0x4d5410 "name", type_tag = 0x4d133e "$", {
        const_value = 0x7fffffffceb0, field_offset = 140737488342704, var_address = 0x7fffffffceb0}}, {kind = 0, 
      name = 0x0, type_tag = 0x0, {const_value = 0x0, field_offset = 0, var_address = 0x0}}}}
__stmt_0 = {source_file = 0x4d5d30 "/home/octavian/Programmierung/bmax/src/bmk/bmk_ng.bmx", line_num = 52, char_num = 0}
__stmt_1 = {source_file = 0x4d5d30 "/home/octavian/Programmierung/bmax/src/bmk/bmk_ng.bmx", line_num = 53, char_num = 0}
__stmt_2 = {source_file = 0x4d5d30 "/home/octavian/Programmierung/bmax/src/bmk/bmk_ng.bmx", line_num = 85, char_num = 0}
__stmt_3 = {source_file = 0x4d5d30 "/home/octavian/Programmierung/bmax/src/bmk/bmk_ng.bmx", line_num = 85, char_num = 0}
__stmt_4 = {source_file = 0x4d5d30 "/home/octavian/Programmierung/bmax/src/bmk/bmk_ng.bmx", line_num = 85, char_num = 0}
__stmt_5 = {source_file = 0x4d5d30 "/home/octavian/Programmierung/bmax/src/bmk/bmk_ng.bmx", line_num = 85, char_num = 0}
__stmt_6 = {source_file = 0x4d5d30 "/home/octavian/Programmierung/bmax/src/bmk/bmk_ng.bmx", line_num = 87, char_num = 0}
woollybah commented 9 years ago

I've been unable to replicate this so far. Both on OS X and Linux, it has run okay for me as a debug build.

If you just want to use bmk, you can always do a release build, in which case the debug stack stuff is not included as part of the source.

GWRon commented 9 years ago

@woollybah Did you check with the "daily build" of ubuntu 15.04? Maybe some things changed there (eg. gcc version is 4.9.2 there, mine on Mint 17 is still "gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)").

@Octav14n Did you have this bug with a stable version of ubuntu too (14.04 LTS or 14.10)?.

woollybah commented 9 years ago

I'm also using 64-bit Mint 17 with 4.8.2. I'll look at setting up a new VM tonight with the latest stuff - but the generated code won't change between versions of the OS/GCC.

Octav14n commented 9 years ago

OK, I've found a few more details:

  1. I've written "makemods" wrong the whole time (I used singular "makemod"), the "comandline error" didn't appear though because the bug was caused before the check (i think).
  2. after adding (emtpy) "config.bmk" and "custom.bmk" everything works fine. If I delete one of those, the error reappears.
woollybah commented 9 years ago

Thanks. I'll look into the missing file problem.

GWRon commented 9 years ago

you mean if you remove an empty "custom.bmk" it does fail somewhere? This should not happen, as it just "returns" if the file is not existing (see bmk_ng.bmx: LoadBMK()).

hmmm but ... please check if you have another custom.bmk somewhere. Why? LoadBMK checks there:

so this might lead to: /home/user/BlitzMaxNG/bmx/custom.bmk" /home/user/BlitzMaxNG/bmx/home/user/BlitzMaxNG/bmx/custom.bmk" or /something/else//home/user/BlitzMaxNG/bmx/custom.bmk

Especially the last variant might be the path to another existing file (dunno about the double slash).

EDIT: Suggestion: LoadBMK should only check "other folders" if the path does not start with an "/" or "{char}:" -> absolute paths. Or did I miss obvious reasons?

Octav14n commented 9 years ago

So my stacktrace suggests that bmk_ng.bmx line 81 is where the error happens

Method LoadBMK(path:String)
        Local str:String
        Try
            [snip]
        Catch e:Object
            Try
                [snip]
            Catch e:Object
                ' we tried... twice
                ' fail silently...
                Return ' <-- this Return is listed in my StackTrace (see first post)
            End Try
        End Try
        [snip]

The inner Catch-Block is translated to this C-Code (line 747 is marked):

bbOnDebugPopExState();
BBOBJECT ex = bbExObject();
if (bbObjectDowncast(ex,&bbObjectClass) != &bbNullObject) {
    BBOBJECT bbt_e2=(BBOBJECT)ex;
    struct BBDebugScope_1 __scope = {
        BBDEBUGSCOPE_LOCALBLOCK,
        0,
        {
            {
                BBDEBUGDECL_LOCAL,
                "e",
                ":Object",
                .var_address=&bbt_e2
            },
            BBDEBUGDECL_END 
        }
    };
    bbOnDebugEnterScope(&__scope);
    struct BBDebugStm __stmt_0 = {"/home/octavian/Programmierung/bmax/src/bmk/bmk_ng.bmx", 81, 0};
    bbOnDebugEnterStm(&__stmt_0);
    bbOnDebugLeaveScope();
    bbOnDebugLeaveScope(); // <-- This line is marked in my Stacktrace
    bbOnDebugLeaveScope();
    return;
} else  {
    bbExThrow(ex);
}

And at last: $BUILDPATH is not set. AppDir should be /home/octavian/Programmierung/bmax

$ find /home/octavian -name "custom.bmk" 2>/dev/null /home/octavian/Programmierung/bmax/bin/custom.bmk /home/octavian/Programmierung/bmax/src/bmk/custom.bmk

The first one is the one i added (empty, if I delete this one the bug happens) The second one is the one from git. src/bmk is my git clone directory.

Octav14n commented 9 years ago

I've condensed my error to the following: compiled using ./bin/bmk makeapp -a -g x64 -x test/catch.bmx

SuperStrict
Framework brl.appstub

myLoadBMK()

Function myLoadBMK()
    Try
        Return ' <-- This Return causes my error.
    End Try
End Function

Edit: this is also bugging on 32bit build: ./bin/bmk makeapp -a -g x86 -x test/catch.bmx

woollybah commented 9 years ago

Thanks. I'll push a fix later.

woollybah commented 9 years ago

Should be okay now.