11# -*- coding: utf-8 -*-
22#
3- # Copyright (C) 2008-2009, 2013-2017, 2019-2021, 2023-2024 Rocky
3+ # Copyright (C) 2008-2009, 2013-2017, 2019-2021, 2023-2025 Rocky
44# Bernstein <rocky@gnu.org>
55#
66# This program is free software: you can redistribute it and/or modify
3636
3737import os
3838import sys
39+ import traceback
3940from typing import Callable , Literal , Optional
4041
4142from trepan .debugger import Trepan , debugger_obj
4243from trepan .interfaces .server import ServerInterface
44+ from trepan .lib .default import DEBUGGER_SETTINGS
4345from trepan .post_mortem import post_mortem_excepthook , uncaught_exception
4446
4547DEFAULT_DEBUG_PORT : Literal = 1955
4648
49+
4750def debug (
4851 dbg_opts = {},
4952 start_opts = None ,
@@ -194,11 +197,20 @@ def debug_for_remote_access():
194197 """Enter the debugger in a mode that allows connection to it
195198 outside of the process being debugged.
196199 """
197- connection_opts = {'IO' : 'TCP' , 'PORT' : os .getenv ('TREPAN3K_TCP_PORT' , DEFAULT_DEBUG_PORT )}
200+ connection_opts = {
201+ "IO" : "TCP" ,
202+ "PORT" : os .getenv ("TREPAN3K_TCP_PORT" , DEFAULT_DEBUG_PORT ),
203+ }
198204 intf = ServerInterface (connection_opts = connection_opts )
199- dbg_opts = {'interface' : intf }
200- print (f'Starting { connection_opts ["IO" ]} server listening on { connection_opts ["PORT" ]} .' , file = sys .stderr )
201- print (f'Use `python3 -m trepan.client --port { connection_opts ["PORT" ]} ` to enter debugger.' , file = sys .stderr )
205+ dbg_opts = {"interface" : intf }
206+ print (
207+ f'Starting { connection_opts ["IO" ]} server listening on { connection_opts ["PORT" ]} .' ,
208+ file = sys .stderr ,
209+ )
210+ print (
211+ f'Use `python3 -m trepan.client --port { connection_opts ["PORT" ]} ` to enter debugger.' ,
212+ file = sys .stderr ,
213+ )
202214 debug (dbg_opts = dbg_opts , step_ignore = 0 , level = 1 )
203215
204216
@@ -210,7 +222,7 @@ def debugger_on_post_mortem():
210222
211223def run_eval (
212224 expression ,
213- debug_opts : Optional [dict ] = None ,
225+ debug_opts : Optional [dict ] = DEBUGGER_SETTINGS ,
214226 start_opts : Optional [dict ] = None ,
215227 globals_ : Optional [dict ] = None ,
216228 locals_ : Optional [dict ] = None ,
@@ -235,7 +247,7 @@ def run_eval(
235247 dbg .core .trace_hook_suspend = True
236248 if start_opts and "tb_fn" in start_opts :
237249 tb_fn = start_opts ["tb_fn" ]
238- uncaught_exception ( dbg , tb_fn )
250+ traceback . print_exc ( )
239251 finally :
240252 dbg .core .trace_hook_suspend = False
241253 return
@@ -244,7 +256,7 @@ def run_eval(
244256def run_call (
245257 func : Callable ,
246258 * args ,
247- debug_opts : Optional [dict ] = None ,
259+ debug_opts : Optional [dict ] = DEBUGGER_SETTINGS ,
248260 start_opts : Optional [dict ] = None ,
249261 ** kwds ,
250262):
@@ -265,7 +277,13 @@ def run_call(
265277 return
266278
267279
268- def run_exec (statement , debug_opts = None , start_opts = None , globals_ = None , locals_ = None ):
280+ def run_exec (
281+ statement ,
282+ debug_opts : Optional [dict ] = DEBUGGER_SETTINGS ,
283+ start_opts = None ,
284+ globals_ = None ,
285+ locals_ = None ,
286+ ):
269287 """Execute the statement (given as a string) under debugger
270288 control starting with the statement subsequent to the place that
271289 this run_call appears in your program.
0 commit comments