• Strykker@programming.dev
    link
    fedilink
    arrow-up
    126
    arrow-down
    1
    ·
    8 months ago

    Except the C++ “Core dumped” line is telling you it just wrote a file out with the full state of the program at the time of the crash, you can load it up and see where it crashed and then go and look at what every local variable was at the time of the crash.

    Pretty sure you can even step backwards in time with a good debugger to find out exactly how you got to the state you’re currently in.

              • TarantulaFudge@lemmy.ml
                link
                fedilink
                arrow-up
                5
                ·
                8 months ago

                I love gdb! I recently had to do a debug and wow its so cool! On gentoo I can compile everything with symbols and source and can do a complete stack trace.

              • inetknght@lemmy.ml
                link
                fedilink
                arrow-up
                5
                ·
                8 months ago

                …unless you build the executable with optimizations that remove the stack frame. Good luck debugging that sucker!

              • TangledHyphae@lemmy.world
                link
                fedilink
                arrow-up
                2
                ·
                8 months ago

                Am I the only one in this thread who uses VSCode + GDB together? The inspection panes and ability to breakpoint and hover over variables to drill down in them is just great, seems like everyone should set up their own c_cpp_properties.json && tasks.json files and give it a try.

          • current@lemmy.ml
            link
            fedilink
            arrow-up
            8
            arrow-down
            9
            ·
            8 months ago

            i mean you’re expected to know the basic functioning of the compiler when you use it

          • ysjet@lemmy.world
            link
            fedilink
            English
            arrow-up
            8
            arrow-down
            16
            ·
            8 months ago

            Imagine if you knew the most basic foundational features of the language you were using.

            Next we’ll teach you about this neat thing called the compiler.

            • Russ@bitforged.space
              link
              fedilink
              English
              arrow-up
              10
              ·
              8 months ago

              I’m not a C/C++ dev, but isn’t apport Ubuntu’s crash reporter? Why would dumps be going into there?

              Though on a rhetorical thought, I am aware of systemd’s coredumptctl so perhaps its collecting dumps the same way systemd does.

              • ysjet@lemmy.world
                link
                fedilink
                English
                arrow-up
                10
                ·
                edit-2
                8 months ago

                https://wiki.ubuntu.com/Apport

                It intentionally acts as an intercept for such things, so that core dumps can be nicely packaged up and sent to maintainers in a GUI-friendly way so maintainers can get valuable debugging information even from non-tech-savvy users. If you’re running something on the terminal, it won’t be intercepted and the core dump will be put in the working directory of the binary, but if you executed it through the GUI it will.

                Assuming, of course, you turn crash interception on- it’s off by default since it might contain sensitive info. Apport itself is always on and running to handle Ubuntu errors, but the crash interception needs enabled.

  • FlatFootFox@lemmy.world
    link
    fedilink
    arrow-up
    73
    ·
    8 months ago

    My favorite compile error happened while I was taking a Haskell class.

    ghc: panic! (the ‘impossible’ happened)

    The issue is plainly stated, and it provides clear next steps to the developer.

    • Ignotum@lemmy.world
      link
      fedilink
      arrow-up
      46
      ·
      8 months ago

      I had a similar error, though not from the compiler
      Error message just read this should never happen

      • merc@sh.itjust.works
        link
        fedilink
        arrow-up
        0
        ·
        8 months ago

        Find me anyone who claims they use tabs for indentation, and I bet I’ll find at least one case where they’re using both tabs and spaces.

        The only safe way to avoid war crimes is to avoid tabs.

    • xigoi@lemmy.sdf.org
      link
      fedilink
      arrow-up
      21
      ·
      8 months ago

      Good. Spaces and tabs for indentation should never be mixed in any language other than Whitespace.

      • Faresh@lemmy.ml
        link
        fedilink
        English
        arrow-up
        4
        ·
        edit-2
        8 months ago

        Some people use tabs for indentation and spaces for alignment. It kind of gets the pros of tabs (user configurable indent-width) and the pros of spaces (alignment). That doesn’t work in Python where you can’t align stuff and the interpreter doesn’t allow mixing tabs with spaces, but in other languages it is a possible style.

  • ElCanut@jlai.lu
    link
    fedilink
    arrow-up
    66
    arrow-down
    3
    ·
    edit-2
    8 months ago

    Rust developer: I’d like to compile some code

    Rust compiler: the fuck you are

    • Malle_Yeno@pawb.social
      link
      fedilink
      arrow-up
      38
      ·
      8 months ago

      The rust compiler holds your hand, wraps you in blankets, makes you hot chocolate, kisses you on the forehead before it gently and politely points out what you did wrong and how you can solve it step-by-step. It would never think of something as heinous as swearing at you, shame on you for insulting my wife’s honour like this.

    • henfredemars
      link
      fedilink
      English
      arrow-up
      35
      arrow-down
      2
      ·
      edit-2
      8 months ago

      Yes. It’s a surprisingly bad debugger the more you think about it. I use it largely in assembly and it loves to spit out random errors about memory it tried to access based on the current register state. The shortcuts are kind of dumb.

      It certainly works but I wouldn’t call it a pleasure to use.

      Ex: try disp x/1i $eip often just doesn’t work.

      • TunaCowboy@lemmy.world
        link
        fedilink
        arrow-up
        5
        ·
        8 months ago

        I use gdb with great success for x64, rv64, and c:

        info registers rip or just setup tui:

        # ~/.config/gdb/gdbinit:
        tui new-layout default regs 1 {-horizontal src 1 asm 1} 2 status 0 cmd 1
        tui layout default
        tui enable
        
      • xan1242@lemmy.ml
        link
        fedilink
        arrow-up
        2
        arrow-down
        1
        ·
        8 months ago

        I honestly vastly prefer using IDA and Windows specific tools (x64dbg) over gdb. IDA can interface with gdb so it can act as a frontend which can be handy for visualization.

  • Flxibit@lemmy.world
    link
    fedilink
    arrow-up
    34
    ·
    8 months ago

    This C++ message has an urgency vibes to it:

    “Segmentation fault!! Drop the Nuclear Reactor quick!!”

  • voxel@sopuli.xyz
    link
    fedilink
    arrow-up
    25
    ·
    edit-2
    8 months ago
    gdb ./fuck
    r
    where
    

    you should get a complete stack trace (complete with values of some function arguments)

    • OpenStars@startrek.website
      link
      fedilink
      English
      arrow-up
      12
      arrow-down
      8
      ·
      8 months ago

      This right here - C++ iirc is used mostly for microprocessor code in an industry setting, where EXTENSIVE testing is done so that bloated code doesn’t need to constantly check for programmer errors every single time, i.e. where execution speed is prioritized over programmer development time. And whenever that is not the case, well, as OP pointed out, other higher-level languages also exist (implication: to choose from).

      • Backslash@feddit.de
        link
        fedilink
        arrow-up
        32
        ·
        8 months ago

        C++ iirc is used mostly for microprocessor code

        lol no, it’s used almost everywhere where performance is important and people want(ed) OOP, from tiny projects to web browsers (Chrome, Firefox) to game engines (Unreal, CryEngine). Many of these are hugely complex and do encounter segfaults on a somewhat frequent basis.

        Saying C++ is mostly used for embedded applications is like saying C# is mostly used for scripting games, i.e. it doesn’t nearly cover all the use cases.

        higher-level languages also exist

        This depends on your definition of “higher-level”, but many people would argue that C++ is on a similar level to Java or C# in terms of abstraction. The latter two do, however, have a garbage collector, which vastly simplifies memory management for the programmer(generally anyway).

        • tool@lemmy.world
          link
          fedilink
          English
          arrow-up
          2
          ·
          8 months ago

          Lots of those in C# now, especially with Unity coming along like it did.

      • scrion@lemmy.world
        link
        fedilink
        arrow-up
        6
        ·
        8 months ago

        I also currently use it for a new project since all needed 3rd party libraries are from a very specific domain and the project has a deadline, so writing and testing wrappers for Rust that would provide me with any meaningful advantages down the road are too costly to budget for before the deadline.

        That could become part of a future refactoring, though.

  • Subverb@lemmy.world
    link
    fedilink
    arrow-up
    22
    arrow-down
    3
    ·
    8 months ago

    Nevermind that the C++ program is two orders of magnitude faster when completed.

    I would love to learn and use Rust but I’m a embedded systems guy. Everything of consequence is C and C++.

  • AMDIsOurLord@lemmy.ml
    link
    fedilink
    arrow-up
    19
    arrow-down
    1
    ·
    8 months ago

    The developer must either provide the logging and attach a debugger or go get fucked when a runtime error happens

    • Faresh@lemmy.ml
      link
      fedilink
      arrow-up
      11
      arrow-down
      1
      ·
      edit-2
      8 months ago

      That’s not true though. You can get the backtrace and other useful information from the coredump mentioned by the error message by loading it with gdb. Not as good as attaching it to a living process, since you can’t see step-by-step what happens leading up to the error, but still quite useful.

      • AMDIsOurLord@lemmy.ml
        link
        fedilink
        arrow-up
        3
        ·
        8 months ago

        Well yes, that’s a pretty good way of debugging a third party app but if you are developing something you can have more ease with gdb attached

    • drolex@sopuli.xyz
      link
      fedilink
      arrow-up
      6
      ·
      8 months ago

      You can also debug post-mortem with the minidump or the core dump file with WDT on Windows. Great fun and a good way to brush up on your assembly skills

      • marcos@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        8 months ago

        Great fun and a good way to brush up on your assembly skills

        Just load it on the debugger and leave your asm skill gather patina.