"GDB" style source level debugging for P2 C - a work in progress.

Demo of techniques for setting traps/breakpoints in C programs compiled under Flex GUI. Preliminary. Try it!!!

"Application" is a number base conversion program that can handle ridiculous input like 5661654161651461616541611 and convert to/from "any" base, such as base 2, base 16, decimal time, base 137 or whatever. See what happens when you enter 3.14159 when it asks for INTEGER input.

Now about those pesky primes or those billion digits of pi???? Hmmmmm.

Comments

  • You might want to add "#include <string.h>" to make sure this compiles in flexgui for everyone...


    dgately
  • O.K. added string.h for compatibility reasons, even though the original code did not appear to need it. Continuing to work on disassembler, and other functions. Usage is pretty simple. Just add some macros and functions to your code as needed so that you can try to figure out what is going on when things get really strange. Stack traces are actually very helpful here.
    Essentially adding something like this to your code will enable the creation of the needed trap variables and breakpoints.

    _TRACE_DEBUG_(TRAP,0xdeadbeef)
    _BREAK_DEBUG_("chartobase36(char c)",__LINE__,&TRAP);


    ( Entering terminal mode.  Press Ctrl-] to exit. )
    
    Type in a long integer:
    >111111111111111111111111111111111
    33 bins filled:
    Enter base to convert from:
    >2
    1 bins filled:
    Converting string with size 1 ...
    Iteration 1: bin value is 2, summation is 2.
    Enter base to convert to:
    >10
    2 bins filled:
    Converting string with size 2 ...
    Iteration 1: bin value is 1, summation is 1.
    Iteration 2: bin value is 0, summation is 10.
    Converting from base 2 to base 10 ...
    Compressing to base 16:
    Converting from base 16 to base 100 ...
    Squaring the binfactor array:
    {(2),(56)} (base one-hundred)
    Squaring the binfactor array:
    {(6),(55),(36)} (base one-hundred)
    Squaring the binfactor array:
    {(42),(94),(96),(72),(96)} (base one-hundred)
    Expanding from base 100 to base 10:
    8589934591
    
    Type in a long integer:
    >86400
    5 bins filled:
    Enter base to convert from:
    >10
    2 bins filled:
    Converting string with size 2 ...
    Iteration 1: bin value is 1, summation is 1.
    Iteration 2: bin value is 0, summation is 10.
    Enter base to convert to:
    >60
    2 bins filled:
    Converting string with size 2 ...
    Iteration 1: bin value is 6, summation is 6.
    Iteration 2: bin value is 0, summation is 60.
    Converting from base 10 to base 60 ...
    Compressing to base 100:
    Converting from base 100 to base 121 ...
    Squaring the binfactor array:
    {(82),(78)} (base one-hundred and twenty-one)
    Expanding from base 121 to base 11:
    Converting from base 11 to base 60 ...
    Squaring the binfactor array:
    {(2),(1)} (base sixty)
    Squaring the binfactor array:
    {(4),(4),(1)} (base sixty)
    24:00:00
    
    Type in a long integer:
    >3.14159
    ***DEBUG BREAKPOINT REACHED***
    Context = chartobase36(char c), Line number = 591
    Address: 0000c158: Value:         2048 | 0x00000800 |   ASCII  (
    Address: 0000c15c: Value:            1 | 0x00000001 |   ASCII !
    Address: 0000c160: Value:            0 | 0x00000000 |   ASCII
    Address: 0000c164: Value:            3 | 0x00000003 |   ASCII #
    Address: 0000c168: Value:            1 | 0x00000001 |   ASCII !
    Address: 0000c16c: Value:            7 | 0x00000007 |   ASCII '
    Address: 0000c170: Value:        49198 | 0x0000c02e |   ASCII .@
    Address: 0000c174: Value:  -2147481888 | 0x800006e0 |   ASCII `&
    Address: 0000c178: Value:  -2147476664 | 0x80001b48 |   ASCII H;
    Address: 0000c17c: Value:            0 | 0x00000000 |   ASCII
    Address: 0000c180: Value:        49480 | 0x0000c148 |   ASCII HA
    Address: 0000c184: Value:  -2147478032 | 0x800015f0 |   ASCII p5
    Address: 0000c188: Value:        44799 | 0x0000aeff |   ASCII .
    Address: 0000c18c: Value:            3 | 0x00000003 |   ASCII #
    Address: 0000c190: Value:   -559038737 | 0xdeadbeef |   ASCII o>-^
    Address: 0000c194: Value:  -2147478052 | 0x800015dc |   ASCII \5
    Press ANY key to continue or ESC to DEBUG
    :
    :?
    'a'=ASSEMBLE, 'b'=BREAKPOINTS(CLEAR/DISABLE/ENABLE/SET)
    'c'=CPU (Info, Status, Change CPU Type), 'd'=DOWN
    'e'=EVAL(expression), 'l'=LIST(disassembly), 'm'=MONITOR
    'p'=PROCESS, 'r'=RUN/RESUME,'s'=STACK TRACE, 'u'=UP
    'w'=WATCH VARIABLE, 'x'=EXAMINE, 'z'=ZAP, '?'=THIS MENU
    :l
    Dissassmeble (LIST) at? default = (*0000c194) = 800015dc:
    800015dc: (f1049408) FLAGS=f CODE=   8 _add_    __I DEST=004a, SOURCE=0008
    800015e0: (fb00a64a) FLAGS=f CODE=  88 _rdlong_ ___ DEST=0053, SOURCE=004a
    800015e4: (f1849408) FLAGS=f CODE=  12 addsx    __I DEST=004a, SOURCE=0008
    800015e8: (f603f04a) FLAGS=f CODE=  48 _mov_    ___ DEST=01f8, SOURCE=004a
    800015ec: (fdc00023) FLAGS=f CODE= 110 _calla_  ___ DEST=0000, SOURCE=0023
    800015f0: (fd64002e) FLAGS=f CODE= 107 cogid/exit __I DEST=0000, SOURCE=002e
    800015f4: (f604280d) FLAGS=f CODE=  48 _mov_    __I DEST=0014, SOURCE=000d
    800015f8: (fdc00016) FLAGS=f CODE= 110 _calla_  ___ DEST=0000, SOURCE=0016
    800015fc: (f6013e7f) FLAGS=f CODE=  48 _mov_    ___ DEST=009f, SOURCE=007f
    80001600: (fb01409f) FLAGS=f CODE=  88 _rdlong_ ___ DEST=00a0, SOURCE=009f
    80001604: (f1053e10) FLAGS=f CODE=   8 _add_    __I DEST=009f, SOURCE=0010
    80001608: (fb01429f) FLAGS=f CODE=  88 _rdlong_ ___ DEST=00a1, SOURCE=009f
    8000160c: (f1853e10) FLAGS=f CODE=  12 addsx    __I DEST=009f, SOURCE=0010
    80001610: (ff000003) FLAGS=f CODE= 120 GNU      ___ DEST=0000, SOURCE=0003
    80001614: (f60545ff) FLAGS=f CODE=  48 _mov_    __I DEST=00a2, SOURCE=01ff
    80001618: (f60146a2) FLAGS=f CODE=  48 _mov_    ___ DEST=00a3, SOURCE=00a2
    8000161c: (f0654602) FLAGS=f CODE=   3 sbr      __I DEST=00a3, SOURCE=0002
    80001620: (f10146a0) FLAGS=f CODE=   8 _add_    ___ DEST=00a3, SOURCE=00a0
    80001624: (fb0948a3) FLAGS=f CODE=  88 _rdlong_ _Z_ DEST=00a4, SOURCE=00a3
    80001628: (a1854401) FLAGS=a CODE=  12 addsx    __I DEST=00a2, SOURCE=0001
    8000162c: (ad9fffe8) FLAGS=a CODE= 108 _jmp_    CZI DEST=01ff, SOURCE=01e8
    80001630: (f604fe00) FLAGS=f CODE=  48 _mov_    __I DEST=007f, SOURCE=0000
    80001634: (fdd0298c) FLAGS=f CODE= 110 _calla_  C__ DEST=0014, SOURCE=018c
    80001638: (f25d4432) FLAGS=f CODE=  18 cmps     CZI DEST=00a2, SOURCE=0032
    8000163c: (ed900054) FLAGS=e CODE= 108 _jmp_    C__ DEST=0000, SOURCE=0054
    80001640: (f6018ca2) FLAGS=f CODE=  48 _mov_    ___ DEST=00c6, SOURCE=00a2
    80001644: (f1058c32) FLAGS=f CODE=   8 _add_    __I DEST=00c6, SOURCE=0032
    80001648: (f6058e32) FLAGS=f CODE=  48 _mov_    __I DEST=00c7, SOURCE=0032
    8000164c: (fdc0003f) FLAGS=f CODE= 110 _calla_  ___ DEST=0000, SOURCE=003f
    80001650: (f60148c6) FLAGS=f CODE=  48 _mov_    ___ DEST=00a4, SOURCE=00c6
    80001654: (f6054a32) FLAGS=f CODE=  48 _mov_    __I DEST=00a5, SOURCE=0032
    80001658: (f1814aa4) FLAGS=f CODE=  12 addsx    ___ DEST=00a5, SOURCE=00a4
    8000165c: (f25d4a01) FLAGS=f CODE=  18 cmps     CZI DEST=00a5, SOURCE=0001
    :r
    ***DEBUG BREAKPOINT REACHED***
    Context = chartobase36(char c), Line number = 591
    Address: 0000c158: Value:         2048 | 0x00000800 |   ASCII  (
    Address: 0000c15c: Value:            1 | 0x00000001 |   ASCII !
    Address: 0000c160: Value:            0 | 0x00000000 |   ASCII
    Address: 0000c164: Value:            3 | 0x00000003 |   ASCII #
    Address: 0000c168: Value:            1 | 0x00000001 |   ASCII !
    Address: 0000c16c: Value:            7 | 0x00000007 |   ASCII '
    Address: 0000c170: Value:        49198 | 0x0000c02e |   ASCII .@
    Address: 0000c174: Value:  -2147481888 | 0x800006e0 |   ASCII `&
    Address: 0000c178: Value:  -2147476624 | 0x80001b70 |   ASCII p;
    Address: 0000c17c: Value:            0 | 0x00000000 |   ASCII
    Address: 0000c180: Value:        49480 | 0x0000c148 |   ASCII HA
    Address: 0000c184: Value:  -1073736208 | 0xc00015f0 |   ASCII p5 @
    Address: 0000c188: Value:        44799 | 0x0000aeff |   ASCII .
    Address: 0000c18c: Value:            3 | 0x00000003 |   ASCII #
    Address: 0000c190: Value:   -559038737 | 0xdeadbeef |   ASCII o>-^
    Address: 0000c194: Value:  -2147478052 | 0x800015dc |   ASCII \5
    Press ANY key to continue or ESC to DEBUG
    :r
    :r
    7 bins filled:
    Enter base to convert from:
    >10
    2 bins filled:
    Converting string with size 2 ...
    Iteration 1: bin value is 1, summation is 1.
    Iteration 2: bin value is 0, summation is 10.
    Enter base to convert to:
    >16
    2 bins filled:
    Converting string with size 2 ...
    Iteration 1: bin value is 1, summation is 1.
    Iteration 2: bin value is 6, summation is 16.
    Converting from base 10 to base 16 ...
    Compressing to base 100:
    Converting from base 100 to base 121 ...
    Squaring the binfactor array:
    {(82),(78)} (base one-hundred and twenty-one)
    Squaring the binfactor array:
    {(56),(54),(16),(34)} (base one-hundred and twenty-one)
    Expanding from base 121 to base 11:
    Converting from base 11 to base 16 ...
    Squaring the binfactor array:
    {(7),(9)} (base sixteen)
    Squaring the binfactor array:
    {(3),(9),(3),(1)} (base sixteen)
    3291EF
    
    Type in a long integer:
    >
    
    c
Sign In or Register to comment.