Commit Graph

214 Commits

Author SHA1 Message Date
Augusto Noronha
66748f71eb [DebugInfo] Emit debug info for witness tables
This change emits debug info for witness tables passed into generic
functions when a generic type is constrained to a protocol. This
information is required for LLDB's generic expression evaluator
to work in such functions.

rdar://104446865
2025-04-30 11:18:19 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Adrian Prantl
e4dd71bd87 [IRGenDebugInfo] Cache DIFile pointers instead of file names (NFC)
This is an NFC refactoring that is slightly more efficient and needed for
subsequent commits.
2023-11-29 12:37:06 -08:00
Evan Wilde
7c77fa6f45 Merge branch 'main' into ewilde/update-next
Automerger into next doesn't seem to be working. Manually merging.
2023-06-29 08:33:53 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Felipe de Azevedo Piovezan
22aa61f13f [IRGenDebug] Remove generation of dbg.addr
These intrinsics were removed upstream LLVM and are equivalent to a dbg.value +
OP_deref.
2023-05-12 15:52:58 -04:00
Adrian Prantl
97964f1ba9 Emit debug info for pack count parameters. 2023-02-22 16:16:21 -08:00
Adrian Prantl
06a54432ab Sink isFixedBuffer into DebugTypeInfo and ensure the enclosed types aren't
emitted with the size of the fixed buffer.
2022-12-14 14:18:28 -08:00
Arnold Schwaighofer
189b0ac5e5 IRGen: Emit the proper linkageName debug info of the containing function for async suspend dispatch thunks
Improvement upon #41645 to emit the async suspend dispatch thunk's debug
info with the `linkageName` of the containing function of the async
await.

rdar://88579737
2022-03-03 15:16:41 -08:00
Michael Gottesman
58e2cafa57 [irgen] Add support to IRGenDebugInfo for emitting an llvm.dbg.addr instead of llvm.dbg.declare.
By default, we still use llvm.dbg.declare, so this is an NFC commit. But this
sets us up for using this in the future.
2022-02-15 12:00:31 -08:00
Min-Yih Hsu
2d35d31290 [IRGen][DebugInfo] Use attached SILLocation for generating var debug loc
Currently IRGen requires the AST node of a variable declaration to
generate debug location. However, this will fail if the input is SIL due
to the lack of AST reconstruction. Plus, it's unnecessary since we can
just use the `SILLocation` attached on `debug_value` (and its friends) SIL
instruction to generate the correct LLVM debug metadata.

Resolves SR-14868
2021-07-06 09:40:53 -07:00
Arnold Schwaighofer
5b4e0566b9 [IRGen] Fix debug info for direct arguments/return values
Emit shadow copies in async functions and emit a load to get the value.
2021-03-17 07:41:10 -07:00
Adrian Prantl
b3f5ac3281 Add debug info support for boxed arguments in async functions.
Usually debug info only ever describes the *result* of a projectBox
call. To display a boxed parameter of an async continuation object,
however, the debug info can only describe the box itself and thus also
needs to emit a box type for it so the debugger knows to call into
Remote Mirrors to unbox the value.

SR-14059
rdar://problem/73358988
2021-02-03 14:40:36 -08:00
Erik Eckstein
462e58d3cb SILLocation: a big refactoring and reducing its size from 3 to 2 words
My goal was to reduce the size of SILLocation. It now contains only of a storage union, which is basically a pointer and a bitfield containing the Kind, StorageKind and flags. By far, most locations are only single pointers to an AST node. For the few cases where more data needs to be stored, this data is allocated separately: with the SILModule's bump pointer allocator.

While working on this, I couldn't resist to do a major refactoring to simplify the code:

* removed unused stuff
* The term "DebugLoc" was used for 3 completely different things:
    - for `struct SILLocation::DebugLoc` -> renamed it to `FilePosition`
    - for `hasDebugLoc()`/`getDebugSourceLoc()` -> renamed it to `hasASTNodeForDebugging()`/`getSourceLocForDebugging()`
    - for `class SILDebugLocation` -> kept it as it is (though, `SILScopedLocation` would be a better name, IMO)
* made SILLocation more "functional", i.e. replaced some setters with corresponding constructors
* replaced the hand-written bitfield `KindData` with C bitfields
* updated and improved comments
2021-01-29 20:28:21 +01:00
Nate Chandler
e21550ad90 [SILGen] Enable alternative entry point name.
Previously, the name of the entry point function was always main.  Here,
a new frontend flag is added to enable an arbitrary name to be
specified.

rdar://58275758
2021-01-26 10:43:33 -08:00
Adrian Prantl
0e6a0b84d1 Add debug info support for function arguments in async functions.
This commit depends on changes to the coroutine-splitting pass in LLVM.  Shadow
copies are also turned off for async function arguments, because they make it
impossible to track debug info during coroutine splitting. Instead we are
relying on LLVM's CoroSplit.cpp to emit shadow copies. The Swift frontend gives
CoroSplit license to move do this by describing the arguments using a
dbg.declare intrinsic, even though it points to chain of load/GEP/bitcase
instructions into the Swift context function argument.

rdar://71866936
2020-12-11 16:59:09 -08:00
Toan Nguyen
4b005c4a83 Fix typos in comments 2020-10-27 19:38:16 +07:00
Robert Widmann
eb61931012 [NFC] Grab the private discriminator for a file in IRGenDebugInfo
This was being done at an odd point in the frontend presumably because by that point the private discriminator had been fully computed.  Instead, push the conditions for generating the prefix data down to debug info generation and stop mutating IRGenOptions::DebugFlag in the frontend.
2020-01-13 22:01:41 -08:00
Adrian Prantl
ff22da20c3 Debug Info: Encode let-bindings using DW_TAG_const_type.
This allows the debugger to distinguish constant "let" values from
mutable "var" variables.

rdar://problem/16042546
2019-09-25 08:51:05 -07:00
Erik Eckstein
ffd7f75de3 IRGen: debug info generation for cond_fail messages.
To display a failure message in the debugger, create a function in the debug info which has the name of the failure message.
The debug location of the trap/cond_fail is then wrapped into this function and the function is declared as "inlined".
In case the debugger stops at the trap instruction, it displays the inline function, which looks like the failure message.
For example:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000100000cbf a.out`testit3(_:) [inlined] Unexpectedly found nil while unwrapping an Optional value at test.swift:14:11 [opt]
   11
   12   @inline(never)
   13   func testit(_ a: Int?) -> Int {
-> 14     return a!
   15   }
   16

This change is currently not enabled by default, but can be enabled with the option "-Xllvm -enable-trap-debug-info".
Enabling this feature needs some changes in lldb. When the lldb part is done, this option can be removed and the feature enabled by default.
2019-07-16 14:51:18 +02:00
Brent Royal-Gordon
d5a2912a26 Revert "Better runtime failure messages (not yet enabled by default)" 2019-07-15 13:42:40 -07:00
Erik Eckstein
e915300e96 IRGen: debug info generation for cond_fail messages.
To display a failure message in the debugger, create a function in the debug info which has the name of the failure message.
The debug location of the trap/cond_fail is then wrapped into this function and the function is declared as "inlined".
In case the debugger stops at the trap instruction, it displays the inline function, which looks like the failure message.
For example:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000100000cbf a.out`testit3(_:) [inlined] Unexpectedly found nil while unwrapping an Optional value at test.swift:14:11 [opt]
   11
   12   @inline(never)
   13   func testit(_ a: Int?) -> Int {
-> 14     return a!
   15   }
   16

This change is currently not enabled by default, but can be enabled with the option "-Xllvm -enable-trap-debug-info".
Enabling this feature needs some changes in lldb. When the lldb part is done, this option can be removed and the feature enabled by default.
2019-07-12 14:03:13 +02:00
Slava Pestov
135ce781e2 IRGen: Don't emit debug info for dependent member types
Fixes rdar://40706055
2019-03-02 00:17:15 -05:00
Adrian Prantl
54af8e461f Debug Info: Encode Archetype names in DWARF
Currently LLDB calls into ide::getDeclFromMangledSymbolName() to get
to this information and we would like to get rid of this call.

rdar://problem/47798056
2019-02-20 16:04:16 -08:00
Jordan Rose
d412f4b4ba [IRGen] Adopt std::unique_ptr for IRGenDebugInfo (#19369) 2018-09-18 11:10:10 -07:00
Ellis Hoag
8200916129 Fix debug locations to work well with CodeView
Summary:
There are a few problems with how Swift currently emits location
information for CodeView.

1. WinDbg does not work well with column information so all column
locations must be set to zero.

2. Some instructions, e.g., ``a + b``,  will emit ``@llvm.trap()``
and ``unreachable``. Those instructions should have artificial
locations, i.e., they should have a line location of zero.

3. Some instructions, e.g., ``a / b``, will emit ``unreachable``
sandwiched between other code for that instruction. This makes
WinDbg confused and it cannot decide which set of instructions
to break on. Those instructions should have the same line location
as the others.

4. There are several prologue instructions with artificial line
locations that create breaks in the linetables. Those instructions
should have valid line locations, usually at the start of the
function.

5. Case bodies have cleanup instructions with artificial line
locations unless it has a ``do`` block. Those locations should
be the last line in the case block.

Test Plan:
test/DebugInfo/basic.swift
test/DebugInfo/columns.swift
test/DebugInfo/linetable-codeview.swift
test/DebugInfo/line-directive-codeview.swift
2018-07-18 09:54:19 -07:00
Adrian Prantl
bab3000069 Use depth and index to lookup type metadata artificial variables
instead of using name and decl context.

The advantages of this approach are three-fold:
- This is necessary to support inlined generic functions.
- We can retire the debugger-specific type name manfgling mode for archetypes.
- This saves 270kb of debug information in the x86_64 libSwiftCore.dylib alone.

<rdar://problem/38306256>
2018-06-12 12:48:15 -07:00
Adrian Prantl
2c7a69852b Emits a DW_OP_deref for global variables in a fixed size buffer.
Note that this is only correct unless the variable uses inline
storage. This makes the majority of resilient types in Foundation work
as global variables.  The correct solution would be for LLDB to poke
at the runtime to figure out whether the storage is inline or not, but
until then this is the next best thing.

rdar://problem/39722386
2018-05-02 15:40:16 -07:00
Vedant Kumar
84a652285f [DebugInfo] Remove option to pass None into setCurrentLoc, NFC
Passing in some SILLocation to IRGenDebugInfo setCurrentLoc() will now
be mandatory.

(cherry picked from commit 8bd783fff4)
2018-04-16 10:35:19 -07:00
Vedant Kumar
6b1372206a [DebugInfo] Remove a default location argument from setCurrentLoc
Having a default location of None doesn't seem to enhance readability.

(cherry picked from commit c3ba8ff1ff)
2018-04-16 10:35:18 -07:00
Andrew Trick
53a0676cc2 Revert "[DebugInfo] Set the autogenerated bit to request recycled locations" 2018-04-14 18:48:31 -07:00
Vedant Kumar
8bd783fff4 [DebugInfo] Remove option to pass None into setCurrentLoc, NFC
Passing in some SILLocation to IRGenDebugInfo setCurrentLoc() will now
be mandatory.
2018-04-13 14:50:49 -07:00
Vedant Kumar
c3ba8ff1ff [DebugInfo] Remove a default location argument from setCurrentLoc
Having a default location of None doesn't seem to enhance readability.
2018-04-13 14:38:54 -07:00
David Ungar
1f9a4f3591 Pass around arguments for primary-specific filenames.
Get rid of IRGenOpts attributes that won’t work for batch mode and also remove fakeNamesStub.
2018-02-15 15:34:55 -07:00
Adrian Prantl
efc41d9153 Add a virtual destructor to avoid leaking the new private impl's memory.
rdar://problem/32520596
2017-06-01 15:53:58 -07:00
Adrian Prantl
0cb4a2865d Refactor/Cleanup IRGenDebugInfo to use a private implementation (NFC) 2017-05-03 08:34:06 -07:00
Adrian Prantl
c2b14dccd3 Debug info: Represent clang-imported submodules.
Previously an import of a submodule would emit debug info for
importing the root module.

<rdar://problem/17260802>
2017-05-03 08:33:55 -07:00
Adrian Prantl
5ea2d13f5e Improve the performance of IRGenDebugInfo
This commit changes how inline information is stored in SILDebugScope
from a tree to a linear chain of inlined call sites (similar to what
LLVM is using). This makes creating inlined SILDebugScopes slightly
more expensive, but makes lowering SILDebugScopes into LLVM metadata
much faster because entire inlined-at chains can now be cached. This
means that SIL is no longer preserve the inlining history (i.e., ((a
was inlined into b) was inlined into c) is represented the same as (a
was inlined into (b was inlined into c)), but this information was not
used by anyone.

On my late 2012 i7 iMac, this saves about 4 seconds when compiling the
RelWithDebInfo x86_64 swift standard library — or 40% of IRGen time.

rdar://problem/28311051
2017-04-05 08:33:55 -07:00
Adrian Prantl
b872127b66 Debgger type mangling: Pass GenericEnvironment separate from DeclContext.
This fixes a crash while building the Swift standard library when
partial specializations are enabled.

Eventually we should get rid of needing the DeclContext in the mangled
typename at all, and this is one step towards that goal.

rdar://problem/31253373
2017-03-25 14:09:14 -07:00
Bob Wilson
37e7d1c627 Merge remote-tracking branch 'origin/master' into master-next 2017-01-08 17:07:46 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Bob Wilson
78b28243ff Merge remote-tracking branch 'origin/master' into master-next 2017-01-03 14:22:59 -08:00
practicalswift
ce7a10474f [gardening] Fix accidental double and triple spaces. 2016-12-21 22:13:56 +01:00
Bob Wilson
13da3fa8b1 Merge remote-tracking branch 'origin/master' into master-next 2016-12-04 18:16:09 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Bob Wilson
123865cef5 Use llvm::DINode::DIFlags typed enum to match llvm r280700 2016-10-15 11:02:19 -07:00
Bob Wilson
3fd92f82e8 Use StringRef in more places to match recent llvm changes.
llvm r283043 and possibly other recent changes switch to use StringRef
instead of char* pointers. Update Swift to match. In some cases, this is
a clear improvement. It would be good to assess the impact on memory use,
particularly for the Filename component of source locations.

Note that the change to SILLocation::isNull fixes an apparent bug where
the location was treated as null when the filename was *not* null.
2016-10-15 11:02:07 -07:00
Adrian Prantl
f42dcb9551 Revert "Debug Info: Assert that the main source file name is non-empty."
This reverts commit 3fd5afc6d0.
while investigating buildbot breakage.
rdar://problem/28457719
2016-09-23 16:54:10 -07:00
adrian-prantl
489e80546e Merge pull request #4963 from adrian-prantl/25130236
Assert that the main source file name is non-empty.
2016-09-23 15:36:45 -07:00
Adrian Prantl
3fd5afc6d0 Debug Info: Assert that the main source file name is non-empty.
The Darwin linker won't process the debug info if the source file name
is invalid so there is no point in having a fallback implemented there.

<rdar://problem/25130236>
2016-09-23 10:30:59 -07:00