Skip to content

Commit

Permalink
testing/esp: more extensive GDB logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sobuch authored and erhankur committed Nov 19, 2024
1 parent 03aeab9 commit 2ee1b8b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 32 deletions.
10 changes: 5 additions & 5 deletions testing/esp/debug_backend_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ def create_gdb(self, chip_name, target_triple, toolchain, log_level, log_stream,
extended_remote_mode='127.0.0.1:%d' % dbg.Oocd.GDB_PORT,
log_level=log_level,
log_stream_handler=log_stream,
log_file_handler=log_file)
if len(gdb_log):
_gdb_inst.gdb_set('remotelogfile', gdb_log)
log_file_handler=log_file,
gdb_log_folder=gdb_log)

if debug_oocd > 2:
_gdb_inst.tmo_scale_factor = 5
else:
Expand All @@ -133,13 +133,13 @@ def create_gdb(self, chip_name, target_triple, toolchain, log_level, log_stream,
def create_gdb_and_reconnect(self):
debug_oocd = self.args[0]
log_lev = self.args[1]
gdb_log_file = self.args[2]
gdb_log_folder = self.args[2]
ch = self.args[3]
fh = self.args[4]
connect_tmo = 15

_gdb_inst = self.create_gdb(testee_info.chip, self.toolchain[:-1], self.toolchain, log_lev,
ch, fh, gdb_log_file, debug_oocd)
ch, fh, gdb_log_folder, debug_oocd)
_gdb_inst.connect(tmo=connect_tmo)
_gdb_inst.exec_file_set(self.test_app_cfg.build_app_elf_path())
self.gdb = _gdb_inst
Expand Down
6 changes: 3 additions & 3 deletions testing/esp/py_debug_backend/debug_backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_gdb(chip_name=None,
gdb_path=None,
remote_target=None,
extended_remote_mode=None,
gdb_log_file=None,
gdb_log_folder=None,
log_level=None,
log_stream_handler=None,
log_file_handler=None,
Expand All @@ -61,8 +61,8 @@ def create_gdb(chip_name=None,
gdb_init_args['remote_target'] = remote_target
if extended_remote_mode is not None:
gdb_init_args['extended_remote_mode'] = extended_remote_mode
if gdb_log_file is not None:
gdb_init_args['gdb_log_file'] = gdb_log_file
if gdb_log_folder is not None:
gdb_init_args['gdb_log_folder'] = gdb_log_folder
if log_level is not None:
gdb_init_args['log_level'] = log_level
if log_stream_handler is not None:
Expand Down
22 changes: 14 additions & 8 deletions testing/esp/py_debug_backend/debug_backend/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import time
import re
import shutil
import threading
from pprint import pformat
from pygdbmi.gdbcontroller import GdbController
Expand All @@ -17,7 +18,7 @@ class Gdb(object):
def __init__(self, gdb_path='gdb',
remote_target=None,
extended_remote_mode=False,
gdb_log_file=None,
gdb_log_folder=None,
log_level=None,
log_stream_handler=None,
log_file_handler=None):
Expand All @@ -34,8 +35,8 @@ def __init__(self, gdb_path='gdb',
Use "" or None value to skip the connection stage.
extended_remote_mode : bool
If True extended remote mode should be used.
gdb_log_file : string
path to GDB log file.
gdb_log_folder : string
path to GDB log folder.
log_level : int
logging level for this object. See logging.CRITICAL etc
log_stream_handler : logging.Handler
Expand All @@ -55,15 +56,16 @@ def __init__(self, gdb_path='gdb',
self.stream_handlers = {'console': [], 'target': [], 'log': []}
self._curr_frame = None
self._curr_wp_val = None
self._gdb_log_folder = gdb_log_folder
self._remote_log_count = 0
# gdb config
try:
self.prog_startup_cmdfile = None
self.gdb_set("mi-async", "on")
if gdb_log_file is not None:
pardirs = os.path.dirname(gdb_log_file)
if pardirs:
os.makedirs(pardirs, exist_ok=True) # create non-existing folders
self.gdb_set("logging", "file %s" % gdb_log_file)
if self._gdb_log_folder:
shutil.rmtree(self._gdb_log_folder, ignore_errors=True)
os.makedirs(self._gdb_log_folder)
self.gdb_set("logging file", os.path.join(self._gdb_log_folder, 'gdb.log'))
self.gdb_set("logging", "on")
except Exception as e:
self._logger.error('Failed to config GDB (%s)!', e)
Expand Down Expand Up @@ -554,6 +556,10 @@ def connect(self, tmo=10):
return
self._logger.debug('Connecting to %s', self._remote_target)
remote_mode = 'extended-remote' if self._extended_remote_mode else 'remote'
if self._gdb_log_folder:
self.gdb_set('remotelogfile', os.path.join(self._gdb_log_folder, f'remote_{self._remote_log_count}.log'))
self._remote_log_count += 1

self.target_select(remote_mode, self._remote_target, tmo=tmo)

def disconnect(self):
Expand Down
12 changes: 6 additions & 6 deletions testing/esp/py_debug_backend/debug_backend/hw_specific/esp.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ class GdbEspXtensa(GdbEspImpl, GdbXtensa):
Class to communicate to GDB supporting ESP Xtensa-specific features
"""

def __init__(self, gdb_path, remote_target='127.0.0.1:3333', extended_remote_mode=False, gdb_log_file=None,
def __init__(self, gdb_path, remote_target='127.0.0.1:3333', extended_remote_mode=False, gdb_log_folder=None,
log_level=None, log_stream_handler=None, log_file_handler=None):
GdbXtensa.__init__(self, gdb_path=gdb_path, remote_target=remote_target,
extended_remote_mode=extended_remote_mode, gdb_log_file=gdb_log_file,
extended_remote_mode=extended_remote_mode, gdb_log_folder=gdb_log_folder,
log_level=log_level, log_stream_handler=log_stream_handler,
log_file_handler=log_file_handler)
GdbEspImpl.__init__(self)
Expand Down Expand Up @@ -290,21 +290,21 @@ class GdbEspRiscv(GdbEspImpl, GdbRiscv):
Class to communicate to GDB supporting ESP RISCV-specific features
"""

def __init__(self, gdb_path, remote_target='127.0.0.1:3333', extended_remote_mode=False, gdb_log_file=None,
def __init__(self, gdb_path, remote_target='127.0.0.1:3333', extended_remote_mode=False, gdb_log_folder=None,
log_level=None, log_stream_handler=None, log_file_handler=None):
GdbRiscv.__init__(self, gdb_path=gdb_path, remote_target=remote_target,
extended_remote_mode=extended_remote_mode, gdb_log_file=gdb_log_file,
extended_remote_mode=extended_remote_mode, gdb_log_folder=gdb_log_folder,
log_level=log_level, log_stream_handler=log_stream_handler,
log_file_handler=log_file_handler)
GdbEspImpl.__init__(self)

class GdbEspRiscv32(GdbEspRiscv):

def __init__(self, gdb_path='riscv32-esp-elf-gdb', remote_target='127.0.0.1:3333', extended_remote_mode=False,
gdb_log_file=None, log_level=None, log_stream_handler=None, log_file_handler=None):
gdb_log_folder=None, log_level=None, log_stream_handler=None, log_file_handler=None):
GdbEspRiscv.__init__(self, gdb_path=gdb_path, remote_target=remote_target,
extended_remote_mode=extended_remote_mode,
gdb_log_file=gdb_log_file, log_level=log_level,
gdb_log_folder=gdb_log_folder, log_level=log_level,
log_stream_handler=log_stream_handler,
log_file_handler=log_file_handler)
self.gdb_set('arch', 'riscv:rv32')
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class GdbRiscv(Gdb):
"""
chip_name = 'riscv'

def __init__(self, gdb_path='gdb', remote_target=None, extended_remote_mode=False, gdb_log_file=None,
def __init__(self, gdb_path='gdb', remote_target=None, extended_remote_mode=False, gdb_log_folder=None,
log_level=None, log_stream_handler=None, log_file_handler=None):
super(GdbRiscv, self).__init__(gdb_path=gdb_path, remote_target=remote_target, extended_remote_mode=extended_remote_mode,
gdb_log_file=gdb_log_file, log_level=log_level, log_stream_handler=log_stream_handler,
gdb_log_folder=gdb_log_folder, log_level=log_level, log_stream_handler=log_stream_handler,
log_file_handler=log_file_handler)
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class GdbXtensa(Gdb):
"""
chip_name = 'xtensa'

def __init__(self, gdb_path='gdb', remote_target=None, extended_remote_mode=False, gdb_log_file=None,
def __init__(self, gdb_path='gdb', remote_target=None, extended_remote_mode=False, gdb_log_folder=None,
log_level=None, log_stream_handler=None, log_file_handler=None):
super(GdbXtensa, self).__init__(gdb_path=gdb_path, remote_target=remote_target, extended_remote_mode=extended_remote_mode,
gdb_log_file=gdb_log_file, log_level=log_level, log_stream_handler=log_stream_handler,
gdb_log_folder=gdb_log_folder, log_level=log_level, log_stream_handler=log_stream_handler,
log_file_handler=log_file_handler)
12 changes: 6 additions & 6 deletions testing/esp/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def main():
# start debugger, ideally we should run all tests w/o restarting it
dbg_start(args.toolchain, args.oocd, args.oocd_tcl, board_tcl['files'], board_tcl['commands'],
args.debug_oocd, board_tcl['chip_name'], board_tcl['target_triple'],
log_lev, ch, fh, args.gdb_log_file)
log_lev, ch, fh, args.gdb_log_folder)
res = None
try:
# run tests from the same directory this file is
Expand Down Expand Up @@ -410,7 +410,7 @@ def main():
setup_logger(suite.modules[m].get_logger(), ch, fh, log_lev)
suite.load_app_bins = not args.no_load
global _oocd_inst, _gdb_inst
arg_list = [args.debug_oocd, log_lev, args.gdb_log_file, ch, fh]
arg_list = [args.debug_oocd, log_lev, args.gdb_log_folder, ch, fh]
suite.config_tests(_oocd_inst, _gdb_inst, args.toolchain, board_uart_reader, args.serial_port, arg_list)
# RUN TESTS
res = test_runner.run(suite)
Expand All @@ -423,15 +423,15 @@ def main():
time.sleep(1)
dbg_start(args.toolchain, args.oocd, args.oocd_tcl, board_tcl['files'], board_tcl['commands'],
args.debug_oocd, board_tcl['chip_name'], board_tcl['target_triple'],
log_lev, ch, fh, args.gdb_log_file)
log_lev, ch, fh, args.gdb_log_folder)
err_suite = debug_backend_tests.DebuggerTestsBunch()

ids = [x[0].id() for x in res.errors + res.failures]
for t in suite._tests:
if t.id() in ids:
err_suite.addTest(t)
err_suite.load_app_bins = not args.no_load
arg_list = [args.debug_oocd, log_lev, args.gdb_log_file, ch, fh]
arg_list = [args.debug_oocd, log_lev, args.gdb_log_folder, ch, fh]
err_suite.config_tests(_oocd_inst, _gdb_inst, args.toolchain, board_uart_reader, args.serial_port, arg_list)

# to output new report instead of overwriting previous one
Expand Down Expand Up @@ -497,8 +497,8 @@ def main():
type=int, default=2)
parser.add_argument('--log-file', '-l',
help='Path to log file. Use "stdout" to log to console.')
parser.add_argument('--gdb-log-file', '-gl',
help='Path to GDB log file.', default='')
parser.add_argument('--gdb-log-folder', '-gl',
help='Path to folder for GDB log files.', default='')
parser.add_argument('--serial-port', '-u',
help='Name of serial port to grab board\'s UART output.')
parser.add_argument('--log-uart', '-lu',
Expand Down

0 comments on commit 2ee1b8b

Please sign in to comment.