|
7 | 7 |
|
8 | 8 | # make script compatible with the ancient Python {{{
|
9 | 9 |
|
10 |
| -if re.match(r'^2\.', sys.version): |
| 10 | +LEGACY = re.match(r'^2\.', sys.version) |
| 11 | + |
| 12 | +if LEGACY: |
| 13 | + CONNECTED = False |
11 | 14 | int = long
|
12 | 15 | range = xrange
|
13 | 16 |
|
@@ -662,19 +665,42 @@ def invoke(self, arg, from_tty):
|
662 | 665 | def init(commands):
|
663 | 666 | global LJ_64, LJ_GC64, LJ_FR2
|
664 | 667 |
|
| 668 | + # XXX Fragile: though connecting the callback looks like a crap but it |
| 669 | + # respects both Python 2 and Python 3 (see #4828). |
| 670 | + def connect(callback): |
| 671 | + if LEGACY: |
| 672 | + global CONNECTED |
| 673 | + CONNECTED = True |
| 674 | + gdb.events.new_objfile.connect(callback) |
| 675 | + |
| 676 | + # XXX Fragile: though disconnecting the callback looks like a crap but it |
| 677 | + # respects both Python 2 and Python 3 (see #4828). |
| 678 | + def disconnect(callback): |
| 679 | + if LEGACY: |
| 680 | + global CONNECTED |
| 681 | + if not CONNECTED: |
| 682 | + return |
| 683 | + CONNECTED = False |
| 684 | + gdb.events.new_objfile.disconnect(callback) |
| 685 | + |
| 686 | + try: |
| 687 | + # Try to remove the callback at first to not append duplicates to |
| 688 | + # gdb.events.new_objfile internal list. |
| 689 | + disconnect(load) |
| 690 | + except: |
| 691 | + # Callback is not connected. |
| 692 | + pass |
| 693 | + |
665 | 694 | try:
|
| 695 | + # Detect whether libluajit objfile is loaded. |
666 | 696 | gdb.parse_and_eval('luaJIT_setmode')
|
667 | 697 | except:
|
668 | 698 | gdb.write('luajit-gdb.py initialization is postponed '
|
669 | 699 | 'until libluajit objfile is loaded\n')
|
670 |
| - gdb.events.new_objfile.connect(load) |
| 700 | + # Add a callback to be executed when the next objfile is loaded. |
| 701 | + connect(load) |
671 | 702 | return
|
672 | 703 |
|
673 |
| - try: |
674 |
| - gdb.events.new_objfile.disconnect(load) |
675 |
| - except: |
676 |
| - pass # was not connected |
677 |
| - |
678 | 704 | try:
|
679 | 705 | LJ_64 = str(gdb.parse_and_eval('IRT_PTR')) == 'IRT_P64'
|
680 | 706 | LJ_FR2 = LJ_GC64 = str(gdb.parse_and_eval('IRT_PGC')) == 'IRT_P64'
|
|
0 commit comments