Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes #500

Merged
merged 4 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion s2e_env/commands/forkprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def dump(self):
for v in profile:
mod, rel_pc, count, sym, fcn = v
if v[3]:
print(f'{mod.pid:05d} {os.path.normpath(mod.path)}:{rel_pc:010x} {count:4d}'
print(f'{mod.pid:05d} {os.path.normpath(mod.path)}:{rel_pc:010x} {count:4d} '
f'{os.path.normpath(sym.filename)}:{sym.line} ({fcn.name if fcn else None})')
else:
print(f'{mod.pid:05d} {os.path.normpath(mod.path)}:{rel_pc:#010x} {count:4d} (no debug info)')
Expand Down
1 change: 1 addition & 0 deletions s2e_env/dat/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ dependencies:
- libpixman-1-dev
- libtinfo5
- libpng-dev
- libzstd-dev

# s2e-env dependencies
- lcov
Expand Down
14 changes: 10 additions & 4 deletions s2e_env/symbols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def __init__(self, path, search_paths=None):
def add(self, filename, line, addr):
self._lines.add(filename, line, addr)

def add_all(self, lines):
self._lines = LinesByAddr(lines)

def get(self, addr):
"""
Return line and function information for the given address.
Expand Down Expand Up @@ -337,12 +340,15 @@ def parse(self):

lines = json.loads(stdout_data)

resolved_source_lines = {}

for source_file, data in list(lines.items()):
file_path = guess_source_file_path(self._search_paths, source_file)
for line in data.get('lines', []):
for address in line[1]:
self.add(file_path, line[0], address)
parsed = True
resolved_source_lines[file_path] = data
if data.get('lines', []):
parsed = True

self.add_all(resolved_source_lines)

if parsed:
break
Expand Down
15 changes: 14 additions & 1 deletion s2e_env/symbols/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,22 @@ class LinesByAddr:

__slots__ = ('_lines',)

def __init__(self):
def __init__(self, lines = None):
self._lines = []

if not lines:
return

for file_path, data in list(lines.items()):
for line in data.get('lines', []):
line_number = line[0]
line_addresses = line[1]
for line_address in line_addresses:
sym = LineInfoEntry(file_path, line_number, line_address)
self._lines.append(sym)

self._lines.sort()

def _index(self, x):
# Find rightmost value less than or equal to x
i = bisect.bisect_right(self._lines, x)
Expand Down
33 changes: 21 additions & 12 deletions s2e_env/templates/launch-s2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,27 @@ if [ "x$DEBUG" != "x" ]; then

rm -f gdb.ini

echo handle SIGUSR1 noprint >> gdb.ini
echo handle SIGUSR2 noprint >> gdb.ini
echo set disassembly-flavor intel >> gdb.ini
echo set print pretty on >> gdb.ini
echo set environment S2E_CONFIG=$S2E_CONFIG >> gdb.ini
echo set environment S2E_SHARED_DIR=$S2E_SHARED_DIR >> gdb.ini
echo set environment LD_PRELOAD=$LIBS2E >> gdb.ini
echo set environment S2E_UNBUFFERED_STREAM=1 >> gdb.ini
# echo set environment LIBCPU_LOG_LEVEL=in_asm,int,exec >> gdb.ini
# echo set environment LIBCPU_LOG_FILE=/tmp/log.txt >> gdb.ini
# echo set environment S2E_QMP_SERVER=127.0.0.1:3322 >> gdb.ini
echo set python print-stack full >> gdb.ini
cat <<EOF >gdb.ini
handle SIGUSR1 noprint
handle SIGUSR2 noprint
set disassembly-flavor intel
set print pretty on
set environment S2E_CONFIG=$S2E_CONFIG
set environment S2E_SHARED_DIR=$S2E_SHARED_DIR
set environment LD_PRELOAD=$LIBS2E
set environment S2E_UNBUFFERED_STREAM=1
# set environment LIBCPU_LOG_LEVEL=in_asm,int,exec
# set environment LIBCPU_LOG_FILE=/tmp/log.txt
# set environment S2E_QMP_SERVER=127.0.0.1:3322
set python print-stack full

python
import sys
sys.path.insert(0, '/usr/share/gcc/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
EOF

GDB="gdb --init-command=gdb.ini --args"

Expand Down
Loading