Giter Club home page Giter Club logo

Comments (8)

swift-ci avatar swift-ci commented on July 2, 2024

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.

swift-ci avatar swift-ci commented on July 2, 2024

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.

swift-ci avatar swift-ci commented on July 2, 2024

Comment by Kate Stone (JIRA)

Think about this in the spirit of the request rather than the literal ask.

from llvm-project.

jckarter avatar jckarter commented on July 2, 2024

Thanks Kate. I updated the title to be less prescriptive of the solution.

from llvm-project.

swift-ci avatar swift-ci commented on July 2, 2024

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.

swift-ci avatar swift-ci commented on July 2, 2024

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.

kastiglione avatar kastiglione commented on July 2, 2024

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.

jckarter avatar jckarter commented on July 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.