mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-23 09:43:06 +00:00
b899a10836
enum drgn_register_number in the public libdrgn API and drgn.Register.number in the Python bindings are basically exports of DWARF register numbers. They only exist as a way to identify registers that's lighter weight than string lookups. libdrgn already has struct drgn_register, so we can use that to identify registers in the public API and remove enum drgn_register_number. This has a couple of benefits: we don't depend on DWARF numbering in our API, and we don't have to generate drgn.h from the architecture files. The Python bindings can just use string names for now. If it seems useful, StackFrame.register() can take a Register in the future, we'll just need to be careful to not allow Registers from the wrong platform. While we're changing the API anyways, also change it so that registers have a list of names instead of one name. This isn't needed for x86-64 at the moment, but will be for architectures that have multiple names for the same register (like ARM). Signed-off-by: Omar Sandoval <osandov@osandov.com>
23 lines
667 B
Python
23 lines
667 B
Python
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
# SPDX-License-Identifier: GPL-3.0+
|
|
|
|
import itertools
|
|
import unittest
|
|
|
|
from drgn import Architecture, Platform, PlatformFlags
|
|
|
|
|
|
class TestPlatform(unittest.TestCase):
|
|
def test_default_flags(self):
|
|
Platform(Architecture.X86_64)
|
|
self.assertRaises(ValueError, Platform, Architecture.UNKNOWN)
|
|
|
|
def test_registers(self):
|
|
self.assertIn(
|
|
"rax",
|
|
itertools.chain.from_iterable(
|
|
reg.names for reg in Platform(Architecture.X86_64).registers
|
|
),
|
|
)
|
|
self.assertEqual(Platform(Architecture.UNKNOWN, PlatformFlags(0)).registers, ())
|