Coder Social home page Coder Social logo

change breakpoint syntax? about godebug HOT 11 CLOSED

mailgun avatar mailgun commented on July 3, 2024
change breakpoint syntax?

from godebug.

Comments (11)

omeid avatar omeid commented on July 3, 2024

👍 // godebug: break

Throw an error/warning when a breakpoint is not possible.

from godebug.

glycerine avatar glycerine commented on July 3, 2024

@omeld 's suggestion seems to resolve the problem of improper placement, just error out.

I particularly like this comment based breakpoint idea also because then break points could have meaningful names/phrases attached to them rather than being known by numbers only when enabling/disabling/deleting/making conditional/managing breakpoints.

e.g.

// godebug: break "top of main event loop"

Granted this isn't needed when debugging in, say, emacs; but until you get full source code for context, knowing which breakpoint you've stopped on can instantly give you the relevant context.

from godebug.

jeremyschlatter avatar jeremyschlatter commented on July 3, 2024

Nice, I like the labeled breakpoint idea.

from godebug.

jeremyschlatter avatar jeremyschlatter commented on July 3, 2024

I implemented something different:

_ = "breakpoint"

I prefer the look of // godebug: break, but implementing it was trickier than I expected. Since comments are not part of the AST, it's not clear where to put the breakpoint for a comment in all cases. Here's an example weird case:

for {
    fmt.Println("y")
} // godebug: break

The go/ast package provides a mapping function between AST nodes and associated comments, but there is a fair amount of extra work to do to go from an arbitrary AST statement node to the appropriate place in the tree to insert a breakpoint function call.

_ = "breakpoint, on the other hand, is straightforward. It is parsed as part of the AST. All we have to do is replace its node with the AST representation of godebug.SetTraceGen(ctx).

I considered _ = "godebug: break", but thought it looked too complicated. I expect _ = "breakpoint" to be easier to memorize.

from godebug.

glycerine avatar glycerine commented on July 3, 2024

Very clever solution. I especially like that its a no-op without godebug, so I can leave it in the code. Can _ = "breakpoint" style breakpoints have comments on top? I'm imagining a conditional breakpoint syntax.

for i:=1; i < 200; i++ {
_ = "breakpoint" // if i == 100
}

from godebug.

jeremyschlatter avatar jeremyschlatter commented on July 3, 2024

You can do conditional breakpoints like this for now:

for i:=1; i < 200; i++ {
    if i == 100 {
        _ = "breakpoint"
    }
}

from godebug.

glycerine avatar glycerine commented on July 3, 2024

I know. I just thought it would blow people's minds when they saw it. ;-)

from godebug.

jeremyschlatter avatar jeremyschlatter commented on July 3, 2024

I do like getting to blow people's minds :) I'll think about it.

from godebug.

omeid avatar omeid commented on July 3, 2024

I am not sure if I am liking the new syntax. Having to change code for break points is not the best way to go in my opinion.

I understand that comment basted instrumentation maybe slightly slow but some proper caching can mitigate that issue.

from godebug.

dmitshur avatar dmitshur commented on July 3, 2024

blow people's minds

As far as I know, most users of Go prefer simple, obvious, dumb solutions, rather than shocking, unexpected, complex or mind-blowing. :)

from godebug.

jeremyschlatter avatar jeremyschlatter commented on July 3, 2024

I am not sure if I am liking the new syntax. Having to change code for break points is not the best way to go in my opinion.

What do you think is bad about changing the code like this for a breakpoint?

I understand that comment basted instrumentation maybe slightly slow but some proper caching can mitigate that issue.

Slowness is not the issue with using comment syntax. When I said "there is a fair amount of extra work to do to go from an arbitrary AST statement node to the appropriate place in the tree", I meant that there was a fair amount of extra thought and programming work to do, not that it would be slow at runtime.

_ = "breakpoint" was just a lot easier to implement.

from godebug.

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.