-
Notifications
You must be signed in to change notification settings - Fork 48
GDB: Improve tools to debug vm structures #1396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
franciscozdo
wants to merge
8
commits into
cahirwpz:master
Choose a base branch
from
franciscozdo:gdb-vm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2110cbc
GDB: Improve debugging options for VM subsystem
franciscozdo b41d7ba
GDB: make sparate class for each command
franciscozdo 82b131c
GDB: print pages used in segment
franciscozdo bdb5c8b
Merge branch 'master' into gdb-vm
cahirwpz 8d920f3
Merge branch 'master' into gdb-vm
cahirwpz 89c8306
Apply review changes
franciscozdo 4dd32e4
Update printing pmap
franciscozdo 0c4fe75
Fix AArch64 name
franciscozdo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import gdb | ||
|
|
||
| from .struct import GdbStructMeta | ||
| from .utils import TextTable, cast | ||
| from .utils import TextTable, cast, cast_ptr, get_arch | ||
| from .cmd import UserCommand, CommandDispatcher | ||
|
|
||
|
|
||
|
|
@@ -110,3 +110,54 @@ class Cpu(CommandDispatcher): | |
|
|
||
| def __init__(self): | ||
| super().__init__('cpu', [TLB()]) | ||
|
|
||
|
|
||
| class PageTableMips(): | ||
| def __init__(self, pmap): | ||
| self._pmap = pmap | ||
|
|
||
| def print(self): | ||
| pdp = cast_ptr(self._pmap['pde'], 'pde_t') | ||
| table = TextTable(types='ttttt', align='rrrrr') | ||
| table.header(['vpn', 'pte0', 'pte1', 'pte2', 'pte3']) | ||
| for i in range(1024): | ||
| pde = TLBLo(pdp[i]) | ||
| if not pde.valid: | ||
| continue | ||
| ptp = cast_ptr(pde.ppn, 'pte_t') | ||
| pte = [TLBLo(ptp[j]) for j in range(1024)] | ||
| for j in range(0, 1024, 4): | ||
| if not any(pte.valid for pte in pte[j:j+4]): | ||
| continue | ||
| pte4 = [str(pte) if pte.valid else '-' for pte in pte[j:j+4]] | ||
| table.add_row([f'{(i << 22) + (j << 12):8x}', pte4[0], pte4[1], | ||
| pte4[2], pte4[3]]) | ||
| print(table) | ||
|
|
||
|
|
||
| class PageTableAArch64(): | ||
| def __init__(self, pmap): | ||
| self._pmap = pmap | ||
| print("Page table not implemented for AArch64") | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| def print(self): | ||
| pass | ||
|
|
||
|
|
||
| class PageTableRiscv(): | ||
| def __init__(self, pmap): | ||
| self._pmap = pmap | ||
| print("Page table not implemented for RISC-V") | ||
|
|
||
| def print(self): | ||
| pass | ||
|
|
||
|
|
||
| if get_arch() == 'mips': | ||
| PageTable = PageTableMips | ||
| elif get_arch() == 'aarch64': | ||
| PageTable = PageTableAArch64 | ||
| elif get_arch() == 'riscv': | ||
| PageTable = PageTableRiscv | ||
| else: | ||
| print(f'Arch {get_arch()} not supported') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,10 @@ def cast(value, typename): | |
| return value.cast(gdb.lookup_type(typename)) | ||
|
|
||
|
|
||
| def cast_ptr(value, typename): | ||
| return value.cast(gdb.lookup_type(typename).pointer()) | ||
|
|
||
|
|
||
| def local_var(name): | ||
| return gdb.newest_frame().read_var(name) | ||
|
|
||
|
|
@@ -21,6 +25,14 @@ def relpath(path): | |
| return path.rsplit('sys/')[-1] | ||
|
|
||
|
|
||
| def get_arch(): | ||
| for arch in ['mips', 'aarch64', 'riscv']: | ||
| if arch in gdb.architecture_names(): | ||
| return arch | ||
| print('Current architecture is not supported') | ||
| raise KeyError | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should not it be |
||
|
|
||
|
|
||
| # calculates address of ret instruction within function body (MIPS specific) | ||
| def func_ret_addr(name): | ||
| s = gdb.execute('disass thread_create', to_string=True) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't plan to add more methods to the class in this PR I suggest you convert it to a function. Right now the class looks like an overkill.