-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[lldb] Call FixUpPointer in WritePointerToMemory (try 2) #153585
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
felipepiovezan
wants to merge
8
commits into
llvm:main
Choose a base branch
from
felipepiovezan:felipe/fix_pointers_irmemory
base: main
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.
+93
−0
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ce9c2cc
[lldb] Call FixUpPointer in WritePointerToMemory (try 2)
felipepiovezan 36dcebb
fixup! Improve comment
felipepiovezan 579c985
fixup! Add {} to if statement
felipepiovezan d098df3
fixup! Fix address confusion
felipepiovezan e96470a
fixup! Add test
felipepiovezan 293e1dd
fixup! Clang-format test
felipepiovezan 7f02dbd
fixup! Address test feedback
felipepiovezan 1431f5e
fixup! Fix python formatting
felipepiovezan 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
C_SOURCES := main.c | ||
include Makefile.rules |
50 changes: 50 additions & 0 deletions
50
lldb/test/API/macosx/arm-pointer-metadata-stripping/TestArmPointerMetadataStripping.py
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import lldb | ||
import json | ||
import os | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test import lldbutil | ||
|
||
|
||
@skipIf(archs=no_match(["arm64", "arm64e"])) | ||
class TestArmPointerMetadataStripping(TestBase): | ||
# Use extra_symbols.json as a template to add a new symbol whose address | ||
# contains non-zero high order bits set. | ||
def create_symbols_file(self): | ||
template_path = os.path.join(self.getSourceDir(), "extra_symbols.json") | ||
with open(template_path, "r") as f: | ||
symbols_data = json.load(f) | ||
|
||
target = self.dbg.GetSelectedTarget() | ||
symbols_data["triple"] = target.GetTriple() | ||
|
||
module = target.GetModuleAtIndex(0) | ||
symbols_data["uuid"] = module.GetUUIDString() | ||
|
||
json_filename = self.getBuildArtifact("extra_symbols.json") | ||
with open(json_filename, "w") as file: | ||
json.dump(symbols_data, file, indent=4) | ||
|
||
return json_filename | ||
|
||
def test(self): | ||
self.build() | ||
src = lldb.SBFileSpec("main.c") | ||
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( | ||
self, "break here", src | ||
) | ||
|
||
self.expect_expr("get_high_bits(&x)", result_value="0") | ||
self.expect_expr("get_high_bits(&myglobal)", result_value="0") | ||
|
||
symbols_file = self.create_symbols_file() | ||
|
||
# The high order bits should be stripped. | ||
self.runCmd(f"target module add {symbols_file}") | ||
self.expect_expr("get_high_bits(&myglobal_json)", result_value="0") | ||
|
||
# Mark all bits as used for addresses and ensure bits are no longer stripped. | ||
self.runCmd("settings set target.process.virtual-addressable-bits 64") | ||
self.expect_expr( | ||
"get_high_bits(&myglobal_json)", result_value=str(0x1200000000000000) | ||
) |
21 changes: 21 additions & 0 deletions
21
lldb/test/API/macosx/arm-pointer-metadata-stripping/extra_symbols.json
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"triple": "replace me", | ||
"uuid": "replace me", | ||
"type": "executable", | ||
"sections": [ | ||
{ | ||
"name": "__DATA", | ||
"type": "data", | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"address": 1297224342667202580, | ||
"size": 16 | ||
} | ||
], | ||
"symbols": [ | ||
{ | ||
"name": "myglobal_json", | ||
"size": 8, | ||
"type": "data", | ||
"address": 1297224342667202580 | ||
} | ||
] | ||
} |
20 changes: 20 additions & 0 deletions
20
lldb/test/API/macosx/arm-pointer-metadata-stripping/main.c
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <assert.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
||
|
||
int myglobal = 41; | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
uint64_t get_high_bits(void *ptr) { | ||
uint64_t mask = ~((1ULL << 48) - 1); | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uint64_t ptrtoint = (uint64_t)ptr; | ||
uint64_t high_bits = ptrtoint & mask; | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
printf("Higher bits are = %llx\n", high_bits); | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return high_bits; | ||
} | ||
|
||
int main (){ | ||
int x = 42; | ||
assert(0 == get_high_bits(&x)); | ||
DavidSpickett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return 0; //break here | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.