~rjwills/ensoft-sextant/packaging-fix

« back to all changes in this revision

Viewing changes to src/sextant/objdump_parser.py

  • Committer: Tarmac
  • Author(s): Ben Hutchings
  • Date: 2014-12-18 15:01:01 UTC
  • mfrom: (30.8.7 wierd-names-merge)
  • Revision ID: tarmac-20141218150101-pl5pkixozsekf86i
Function names are now cleaned up by a helper function, which removes __be_ prefixes if they are there (bi-endian builds) and converts names like <name>.<other stuff> to just <name>.

Tests extended to check that this works.

Show diffs side-by-side

added added

removed removed

Lines of Context:
121
121
            print('func {:25} {:15}{}'.format(name, typ, source))
122
122
 
123
123
        def print_call(caller, callee, is_internal):
124
 
            print('call {:25} {:25}'.format(caller, callee))
 
124
            print('call {} {:25} {:25}'.format('EI'[is_internal], caller, callee))
125
125
 
126
126
        def print_started(parser):
127
127
            print('parse started: {}[{}]'.format(self.path, ', '.join(self.sections)))
199
199
                self.add_call(caller, callee, False)
200
200
                self._known_calls.add((caller, callee))
201
201
                self.call_count += 1
202
 
                print(caller, callee)
203
202
            else:
204
203
                self._partial_calls.add((caller, callee))
205
204
 
 
205
    @staticmethod
 
206
    def clean_id(function_identifier):
 
207
        """
 
208
        Clean the funciton identifier string.
 
209
        """
 
210
        # Bi-endian builds add a __be_ prefix to all functions,
 
211
        # get rid of it if it is there,
 
212
        if function_identifier.startswith('__be_'):
 
213
            function_identifier = function_identifier[len('__be_'):]
 
214
 
 
215
        # Some functions look like <identifier>. or <identifier>..<digit>
 
216
        # - get rid of the extra bits here:
 
217
        if '.' in function_identifier:
 
218
            function_identifier = function_identifier.split('.')[0]
 
219
 
 
220
        return function_identifier
 
221
 
 
222
 
206
223
    def parse(self):
207
224
        """
208
225
        Parse self._file.
242
259
                        # <function_name>[@plt]
243
260
                        function_identifier = line.split('<')[-1].split('>')[0]
244
261
 
245
 
                        # IOS builds add a __be_ (big endian) prefix to all functions,
246
 
                        # get rid of it if it is there,
247
 
                        if function_identifier.startswith('__be_'):
248
 
                            function_identifier = function_identifier[len('__be_'):]
 
262
                        function_identifier = self.clean_id(function_identifier)
249
263
 
250
264
                        if '@' in function_identifier:
251
265
                            # Of form <function name>@<other stuff>.
277
291
                            # from which we extract name
278
292
                            callee_is_ptr = False
279
293
                            function_identifier = callee_info.lstrip('<').rstrip('>\n')
280
 
                            if function_identifier.startswith('__be_'):
281
 
                                function_identifier = function_identifier[len('__be_'):]
 
294
                            
 
295
                            function_identifier = self.clean_id(function_identifier) 
282
296
 
283
297
                            if '@' in function_identifier:
284
298
                                callee = function_identifier.split('@')[0]