This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Pal] Fix GDB integration when running non-C apps
Signed-off-by: Michał Kowalczyk <[email protected]>
- Loading branch information
Showing
6 changed files
with
83 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-License-Identifier: LGPL-3.0-or-later */ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
# Copyright (C) 2020 Intel Corporation | ||
# Paweł Marczewski <[email protected]> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
# Copyright (C) 2021 Invisible Things Lab | ||
# Michał Kowalczyk <[email protected]> | ||
|
||
# Commands for temporarily changing source language. Used by other Graphene GDB scripts to ensure | ||
# that a specific source language is used for parsing expressions - GDB interprets scripts using | ||
# the language taken from currently executing code, which may change in time, resulting in scripts | ||
# working only part of the time. | ||
# | ||
# Example: When a GDB script does `if *(uint16_t*)$rip == 0x1234` in a signal catchpoint then it | ||
# will fail with a syntax error if the binary debugged is written in Rust, but only if the signal | ||
# arrived while executing Rust code. | ||
|
||
import re | ||
|
||
import gdb # pylint: disable=import-error | ||
|
||
_g_languages = [] | ||
|
||
|
||
class PushLanguage(gdb.Command): | ||
"""Temporarily change source language and save the old one""" | ||
|
||
def __init__(self): | ||
super().__init__('push-language', gdb.COMMAND_USER) | ||
|
||
def invoke(self, arg, _from_tty): | ||
self.dont_repeat() | ||
|
||
lang_str = gdb.execute('show language', to_string=True).strip() | ||
# ';' is for things like: "auto; currently c" | ||
m = re.match(r'The current source language is "(.*?)[";]', lang_str) | ||
assert m, 'Unexpected output from \'show language\': ' + lang_str | ||
_g_languages.append(m.group(1)) | ||
|
||
gdb.execute('set language ' + arg) | ||
|
||
|
||
class PopLanguage(gdb.Command): | ||
"""Recover source language saved by PushLanguage""" | ||
|
||
def __init__(self): | ||
super().__init__('pop-language', gdb.COMMAND_USER) | ||
|
||
def invoke(self, arg, _from_tty): | ||
self.dont_repeat() | ||
|
||
assert arg == '' | ||
lang = _g_languages.pop() | ||
gdb.execute('set language ' + lang) | ||
|
||
|
||
def main(): | ||
PushLanguage() | ||
PopLanguage() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later */ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
# Copyright (C) 2020 Intel Corporation | ||
# Michał Kowalczyk <[email protected]> | ||
# Paweł Marczewski <[email protected]> | ||
|
@@ -16,7 +16,7 @@ class PushPagination(gdb.Command): | |
"""Temporarily change pagination and save the old state""" | ||
|
||
def __init__(self): | ||
super().__init__("push-pagination", gdb.COMMAND_USER) | ||
super().__init__('push-pagination', gdb.COMMAND_USER) | ||
|
||
def invoke(self, arg, _from_tty): | ||
self.dont_repeat() | ||
|
@@ -34,7 +34,7 @@ class PopPagination(gdb.Command): | |
"""Recover pagination state saved by PushPagination""" | ||
|
||
def __init__(self): | ||
super().__init__("pop-pagination", gdb.COMMAND_USER) | ||
super().__init__('pop-pagination', gdb.COMMAND_USER) | ||
|
||
def invoke(self, arg, _from_tty): | ||
self.dont_repeat() | ||
|
@@ -49,5 +49,5 @@ def main(): | |
PopPagination() | ||
|
||
|
||
if __name__ == "__main__": | ||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later */ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
# Copyright (C) 2021 Invisible Things Lab | ||
# Michał Kowalczyk <[email protected]> | ||
# Copyright (C) 2021 Intel Corporation | ||
# Michał Kowalczyk <[email protected]> | ||
# Paweł Marczewski <[email protected]> | ||
|
||
# Graphene GDB configuration (Linux-SGX specific). | ||
|
||
# Without this GDB would interpret all the expressions below depending on the app code where it just | ||
# happened to stop. | ||
push-language c | ||
|
||
# Prevent the preloaded sgx_gdb.so from being preloaded to the debuggee. | ||
set env LD_PRELOAD= | ||
|
||
|
@@ -26,6 +32,8 @@ condition $bpnum *(uint16_t*)$rip == 0xa20f || *(uint16_t*)$rip == 0x310f | |
commands | ||
silent | ||
|
||
push-language c | ||
|
||
# If we don't disable pagination then successive prints from this handler (even despite it's | ||
# called for different events) will stop and prompt the user for continuation, which is really | ||
# annoying. | ||
|
@@ -39,5 +47,8 @@ commands | |
end | ||
|
||
pop-pagination | ||
pop-language | ||
continue | ||
end | ||
|
||
pop-language |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later */ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
# Copyright (C) 2020 Intel Corporation | ||
# Michał Kowalczyk <[email protected]> | ||
# Paweł Marczewski <[email protected]> | ||
|
@@ -9,15 +9,16 @@ | |
|
||
def main(): | ||
for filename in [ | ||
'common/language_gdb.py', | ||
'common/pagination_gdb.py', | ||
'common/debug_map_gdb.py', | ||
'common/graphene.gdb', | ||
'graphene_sgx.gdb', | ||
]: | ||
print("[%s] Loading %s..." % (os.path.basename(__file__), filename)) | ||
print('[%s] Loading %s...' % (os.path.basename(__file__), filename)) | ||
path = os.path.join(os.path.dirname(__file__), filename) | ||
gdb.execute("source " + path) | ||
gdb.execute('source ' + path) | ||
|
||
|
||
if __name__ == "__main__": | ||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-License-Identifier: LGPL-3.0-or-later */ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
# Copyright (C) 2020 Intel Corporation | ||
# Michał Kowalczyk <[email protected]> | ||
|
||
|
@@ -8,6 +8,7 @@ | |
|
||
def main(): | ||
for filename in [ | ||
'common/language_gdb.py', | ||
'common/pagination_gdb.py', | ||
'common/debug_map_gdb.py', | ||
'common/graphene.gdb', | ||
|