Comments (8)
Comment by Enrico Granata (JIRA)
That would actually be wrong. It is already quite of a hack in Objective-C, where it can lead to random results (e.g. care to guess what 0x1 or 0x5 mean when you pretend it's a pointer?), but at the very least you can somewhat defend it there on the grounds that every object in ObjC is going to have a pointer value
In Swift, not everything that is a Swift object worth talking about has such an obvious pointer value (structs, tuples, enums, anyone?), so pretending that any number could be a pointer is actually not a reasonable behavior, and - again - doing this is already an implementation hack anyway
If you have a number that you know represents a class instance, po unsafeBitCast(0x123, MyClass.self) is what you want to do. And if you don't know that it represents an object of some class - or any class even - we are in no position to make a general educated guess, because again not everything is a class with an attached isa in Swift.
So, sorry, but it po <hex-literal> should NOT replicate the hackery of its ObjC counterpart.
from llvm-project.
Comment by Kate Stone (JIRA)
While it's not entirely obvious that we should be special-casing "po" along these lines, I agree that it's unfortunate that we don't have a simple way to examine references from a raw address.
One possibility is indeed that any Int result that is also an apparently valid pointer for a reference type gets evaluated in this manner, perhaps as one of several representations shown. Running Swift code with something that merely looks valid can be dangerous in its own right and lead to surprising results.
Enrico? Any immediate thoughts about how we'd want to accommodate this scenario?
from llvm-project.
Comment by Kate Stone (JIRA)
Think about this in the spirit of the request rather than the literal ask.
from llvm-project.
Thanks Kate. I updated the title to be less prescriptive of the solution.
from llvm-project.
Comment by Enrico Granata (JIRA)
We have had some discussion about how we might hack this (because I still maintain it is a hack)
One possible way would be for us to have the "po" command be a regular expression command (or, similarly, for the expression parser to recognize if the print-object-description mode is on) such that if the input is merely a number literal (and just a number literal, no pointer arithmetic), then this would turn your expression evaluation into simply generating a const value of the right type (AnyObject, in this case) and the pointer value you passed, and then 'po' that
Obviously, doing that would mean that you end up with things like po 1, po 5, po (IIRC) 137, meaning entirely wrong (and counterintuitive) things - because tagged pointers
from llvm-project.
Comment by Kate Stone (JIRA)
Again, ignore the literal request to use "po 0x<address>" as the syntax. If a user has an address and wants to examine the Swift instance the address points to, what is our solution? Arguably this is something a more raw command like 'frame var 0x<address>' could excel at, though it distorts the meaning of the command beyond recognition and it conflates the notion of how you want to examine it with what you want to examine.
Should po take a parameter that indicates that you aren't providing an expression at all, but rather an address that we want a debug description of? Introducing a fourth command to the frame var / p / po cycle seems less than desirable. Let's talk about this and see where it leads.
from llvm-project.
This issue comes up regularly, and it's three years later. Maybe this discussion can be revisited?
@jckarter it appears you're the only one on this thread still active on bugs.swift.org, would it be good to bring in current lldb folks to weigh in?
from llvm-project.
I pinged friss (JIRA User) about this. Maybe we could provide a Swift library to be automatically loaded into lldb sessions that adds some conveniences to make it easier to turn address literals back into object pointers and/or Swift values.
from llvm-project.
Related Issues (20)
- Infinite recursion in ParseTrieEntries when parsing libGPUCompilerUtils.dylib HOT 1
- Apple Clang: std::source_location returns a wrong result if called in a function parameter.
- xros and visionos compilation support? HOT 4
- Module not found diagnostics are repeated multiply
- Compiler crash while serializing `std::optional` HOT 1
- A request to Apple to open-source the Metal Shading Language compiler
- [CI] apple-llvm-project-PR-windows fails to checkout `release/5.10`
- Usage of RemoteCachingService?
- CAS Unittests broken on Windows HOT 1
- `-finstrument-functions` linking error on Apple clang
- [IR lower bug] Apple's clang generated code will not abort when empty std::string call pop_back(), while llvm/clang do
- Compiler crash on Windows with `-index-store-path` HOT 1
- Compilation fails on Amazon Linux 2023 aarch64 HOT 1
- Doc Comments Are Ignored for Macros HOT 3
- DAP support
- Apple fork clang++ regression in partial specialization templates for hasher
- [HELP]what's the exactly command to build Xcode toolchain from this apple repo? HOT 1
- LLDB never finishes importing Swift modules/setting up Swift reflection HOT 8
- Clang crash: Idx < Size && "access in bound" in AssignmentTrackingAnalysis HOT 5
- Add support for <bit>
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llvm-project.