This is an archive of the discontinued LLVM Phabricator instance.

[NVPTX] Emit debug info in DWARF-2 by default for Cuda devices.
ClosedPublic

Authored by ABataev on Jan 26 2018, 9:11 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

ABataev created this revision.Jan 26 2018, 9:11 AM
tra added inline comments.Jan 26 2018, 10:03 AM
lib/Driver/ToolChains/Cuda.cpp
353 ↗(On Diff #131602)

There's more than one -g option. Presumably you still want -g here for -g{1,2,3} or -ggdb{1,2,3} or -gdwarf2.

Speaking of dwarf, what's going to happen if someone passes -gdwarf5? Should we downgrade it to -gdwarf2 on device side and issue a warning?

test/Driver/cuda-dwarf-2.cu
6–11 ↗(On Diff #131602)

Nit: you could probably collapse all test cases into two: HAS_DEBUG/NO_DEBUG

ABataev added inline comments.Jan 26 2018, 10:18 AM
lib/Driver/ToolChains/Cuda.cpp
353 ↗(On Diff #131602)

That's exactly what I want to avoid. I think we can ignore these options and handle only -g option.
Or I can add a function to ToolChain class to force using the default settings for debugger tuning and DWARF version rather than take them from the driver options.

test/Driver/cuda-dwarf-2.cu
6–11 ↗(On Diff #131602)

Ok, will do

tra added inline comments.Jan 26 2018, 11:04 AM
lib/Driver/ToolChains/Cuda.cpp
353 ↗(On Diff #131602)

You should handle at least -gN/-gline-tables-only/-g. Now that we can emit dwarf debug info, I would want to be able to control it to some degree -- off/line-info-only/full.

I'm still not sure what's the plan for -gdwarfN unsupported on device side?

  • do we ignore it and always emit dwarf2?
  • do we accept it, emit requested version and let user stare at ptxas (or cuda-gdb) errors when it fails to deal with it?
ABataev added inline comments.Jan 26 2018, 11:09 AM
lib/Driver/ToolChains/Cuda.cpp
353 ↗(On Diff #131602)
  1. Ok, will look at this
  2. -gdwarfN should be ignored, we should always emit DWARF2, otherwise, it will break ptxas.
tra added inline comments.Jan 26 2018, 11:15 AM
lib/Driver/ToolChains/Cuda.cpp
353 ↗(On Diff #131602)

Works for me. Please add a test to verify that it's always dwarf2 on device side.

If you want to force DWARF 2, probably clamping the version in LLVM would be simpler? Although most of the debug-info tests are architecture-specific and wouldn't run for an NVPTX target anyway.

If you want to force DWARF 2, probably clamping the version in LLVM would be simpler? Although most of the debug-info tests are architecture-specific and wouldn't run for an NVPTX target anyway.

Hi, I think it would be better to do both: make it default in the frontend and in the backend.

ABataev added inline comments.Jan 30 2018, 9:40 AM
lib/Driver/ToolChains/Cuda.cpp
353 ↗(On Diff #131602)

After some thoughts, I think it would better to follow Paul's suggestion, i.e. force DWARF2 for NVPTX in the backend. In this case, -gdwarfN will not break anything in the debug info for NVPTX.

ABataev updated this revision to Diff 132016.Jan 30 2018, 11:50 AM
  1. Updated after review.
  2. Changed the default behavior of --[no]cuda-noopt-device-debug. If the optimization level is not specified or is O0 and debug info must be emitted, the device debug info is emitted. If optimization level is specified and >O0 and debug info must be emitted, the debug info for device is emitted only if --cuda-noopt-device-debug is specified.
tra added inline comments.Jan 30 2018, 12:02 PM
lib/Driver/ToolChains/Cuda.cpp
436–437 ↗(On Diff #132016)

Do we need to pass -g to make lineinfo debugging work?

ABataev added inline comments.Feb 6 2018, 12:59 PM
lib/Driver/ToolChains/Cuda.cpp
436–437 ↗(On Diff #132016)

I checked with nvcc, it does not send -g in line table only mode.

tra accepted this revision.Feb 8 2018, 11:47 AM

LGTM

This revision is now accepted and ready to land.Feb 8 2018, 11:47 AM

Thanks, will commit it after the commit of the LLVM part

This revision was automatically updated to reflect the committed changes.