11# -*- coding: utf-8 -*-
22#
3- # Copyright (C) 2024 Rocky Bernstein <rocky@gnu.org>
3+ # Copyright (C) 2024-2025 Rocky Bernstein <rocky@gnu.org>
44#
55# This program is free software: you can redistribute it and/or modify
66# it under the terms of the GNU General Public License as published by
1919import os .path as osp
2020import re
2121import sys
22- from inspect import ismodule , currentframe
22+ from inspect import currentframe , ismodule
2323from tempfile import NamedTemporaryFile
2424from types import CodeType
2525
2626import pyficache
2727
28+ from trepan .lib .format import Filename , Hex , LineNumber , Symbol , format_token # Opcode,
2829from trepan .lib .stack import check_path_with_frame , frame2file , is_eval_or_exec_stmt
2930from trepan .processor import cmdfns
3031from trepan .processor .cmdfns import deparse_fn
3132
32- from trepan .lib .format import ( # Opcode,
33- Filename ,
34- Hex ,
35- LineNumber ,
36- Symbol ,
37- format_token ,
38- )
39-
4033try :
4134 from trepan .lib .deparse import deparse_and_cache
4235
@@ -53,7 +46,9 @@ def format_code(code_object: CodeType, style) -> str:
5346 Format according to "style" a Python code object. The
5447 formatted string is returned.
5548 """
56- formatted_line = format_token (LineNumber , str (code_object .co_firstlineno ), style = style )
49+ formatted_line = format_token (
50+ LineNumber , str (code_object .co_firstlineno ), style = style
51+ )
5752 formatted_id = format_token (Hex , hex (id (code_object )), style = style )
5853 formatted_name = format_token (Symbol , code_object .co_name , style = style )
5954 formatted_filename = format_token (Filename , code_object .co_filename , style = style )
@@ -70,14 +65,16 @@ def format_frame(frame_object, style) -> str:
7065 """
7166 formatted_line = format_token (LineNumber , str (frame_object .f_lineno ), style = style )
7267 formatted_id = format_token (Hex , hex (id (frame_object )), style = style )
73- formatted_filename = format_token (Filename , frame_object .f_code .co_filename , style = style )
68+ formatted_filename = format_token (
69+ Filename , frame_object .f_code .co_filename , style = style
70+ )
7471 return (
7572 f"<frame at { formatted_id } "
7673 f"file { formatted_filename } , line { formatted_line } >"
7774 )
7875
7976
80- def print_source_line (msg , lineno , line , event_str = None ):
77+ def print_source_line (msg , lineno , line , event_str = None , is_pyasm : bool = False ):
8178 """Print out a source line of text , e.g. the second
8279 line in:
8380 (/tmp.py:2): <module>
@@ -90,7 +87,10 @@ def print_source_line(msg, lineno, line, event_str=None):
9087
9188 # We don't use the filename normally. ipython and other applications
9289 # however might.
93- return msg (f"{ event_str } { lineno } { line } " )
90+ if is_pyasm :
91+ return msg (f"{ event_str } \n { line } " )
92+ else :
93+ return msg (f"{ event_str } { lineno } { line } " )
9494
9595
9696def print_source_location_info (
@@ -116,6 +116,7 @@ def print_source_location_info(
116116 print_fn (mess )
117117 return
118118
119+
119120def print_location (proc_obj ):
120121 """Show where we are. GUI's and front-end interfaces often
121122 use this to update displays. So it is helpful to make sure
@@ -242,7 +243,15 @@ def prefix_for_filename(deparsed_text: str) -> str:
242243 opts ["style" ] = proc_obj .settings ("style" )
243244
244245 pyficache .update_cache (filename )
246+
247+ is_pyasm = filename .endswith (".pyasm" )
248+ if is_pyasm :
249+ opts = opts .copy ()
250+ opts ["style" ] = "plain"
251+ opts ["output" ] = "plain"
252+
245253 line = pyficache .getline (filename , lineno , opts )
254+
246255 if not line :
247256 if (
248257 not source_text
@@ -290,8 +299,6 @@ def prefix_for_filename(deparsed_text: str) -> str:
290299
291300 pass
292301
293- if isinstance (proc_obj .curframe , int ):
294- breakpoint ()
295302 line = linecache .getline (filename , lineno , proc_obj .curframe .f_globals )
296303 if not line :
297304 m = re .search ("^<frozen (.*)>" , filename )
@@ -343,7 +350,11 @@ def prefix_for_filename(deparsed_text: str) -> str:
343350 if line and len (line .strip ()) != 0 :
344351 if proc_obj .event :
345352 print_source_line (
346- intf_obj .msg , lineno , line , proc_obj .event2short [proc_obj .event ]
353+ intf_obj .msg ,
354+ lineno ,
355+ line ,
356+ proc_obj .event2short [proc_obj .event ],
357+ is_pyasm ,
347358 )
348359 pass
349360 if "<string>" != filename :
@@ -364,11 +375,14 @@ def prefix_for_filename(deparsed_text: str) -> str:
364375 pass
365376 return True
366377
378+
367379# Demo it
368380if __name__ == "__main__" :
381+
369382 def five ():
370383 from trepan .processor .cmdproc import CommandProcessor
371384 from trepan .processor .command .mock import MockDebugger
385+
372386 d = MockDebugger ()
373387 cmdproc = CommandProcessor (d .core )
374388 cmdproc .frame = currentframe ()
0 commit comments