@@ -149,12 +149,12 @@ def change_mapinfo(self, mem_s: int, mem_e: int, mem_p: int = None, mem_info: st
149149 if mem_info is not None :
150150 self .map_info [info_idx ] = (tmp_map_info [0 ], tmp_map_info [1 ], tmp_map_info [2 ], mem_info , tmp_map_info [4 ])
151151
152- def get_mapinfo (self ) -> Sequence [Tuple [int , int , str , str , Optional [ str ] ]]:
152+ def get_mapinfo (self ) -> Sequence [Tuple [int , int , str , str , str ]]:
153153 """Get memory map info.
154154
155155 Returns: A sequence of 5-tuples representing the memory map entries. Each
156156 tuple contains range start, range end, permissions, range label and path of
157- containing image (or None if not contained by any image)
157+ containing image (or an empty string if not contained by any image)
158158 """
159159
160160 def __perms_mapping (ps : int ) -> str :
@@ -166,21 +166,21 @@ def __perms_mapping(ps: int) -> str:
166166
167167 return '' .join (val if idx & ps else '-' for idx , val in perms_d .items ())
168168
169- def __process (lbound : int , ubound : int , perms : int , label : str , is_mmio : bool ) -> Tuple [int , int , str , str , Optional [ str ] ]:
169+ def __process (lbound : int , ubound : int , perms : int , label : str , is_mmio : bool ) -> Tuple [int , int , str , str , str ]:
170170 perms_str = __perms_mapping (perms )
171171
172172 if hasattr (self .ql , 'loader' ):
173173 image = self .ql .loader .find_containing_image (lbound )
174- container = image .path if image and not is_mmio else None
174+ container = image .path if image and not is_mmio else ''
175175 else :
176- container = None
176+ container = ''
177177
178178 return (lbound , ubound , perms_str , label , container )
179179
180180 return tuple (__process (* entry ) for entry in self .map_info )
181181
182- def show_mapinfo (self ):
183- """Emit memory map info in a nicely formatted table.
182+ def get_formatted_mapinfo (self ) -> Sequence [ str ] :
183+ """Get memory map info in a nicely formatted table.
184184 """
185185
186186 mapinfo = self .get_mapinfo ()
@@ -192,12 +192,17 @@ def show_mapinfo(self):
192192 len_addr = max (grouped [0 ])
193193 len_label = max (grouped [1 ])
194194
195- # emit title row
196- self . ql . log . info ( f' { "Start" :{ len_addr }s } { "End" :{ len_addr }s } { "Perm" :5s } { "Label" :{ len_label }s } { "Image" } ' )
195+ # pre-allocate table
196+ table = [ '' ] * ( len ( mapinfo ) + 1 )
197197
198- # emit table rows
199- for lbound , ubound , perms , label , container in mapinfo :
200- self .ql .log .info (f'{ lbound :0{len_addr }x} - { ubound :0{len_addr }x} { perms :5s} { label :{len_label }s} { container or "" } ' )
198+ # add title row
199+ table [0 ] = f'{ "Start" :{len_addr }s} { "End" :{len_addr }s} { "Perm" :5s} { "Label" :{len_label }s} { "Image" } '
200+
201+ # add table rows
202+ for i , (lbound , ubound , perms , label , container ) in enumerate (mapinfo , 1 ):
203+ table [i ] = f'{ lbound :0{len_addr }x} - { ubound :0{len_addr }x} { perms :5s} { label :{len_label }s} { container } '
204+
205+ return table
201206
202207 # TODO: relying on the label string is risky; find a more reliable method
203208 def get_lib_base (self , filename : str ) -> Optional [int ]:
0 commit comments