1 --- 2 title: 'SAOC LLDB D integration: 5th Weekly Update' 3 date: '2021-10-21T01:33:00+01:00' 4 tags: ['saoc', 'saoc2021', 'dlang', 'llvm', 'lldb', 'debug', 'debugging', 'dwarf'] 5 description: "This post describes what I've done on the 5th week of the 6 Symmetry Autumn of Code 2021, including follow up on LLVM patches, researching 7 on DWARF standard tags and attributes, investigation of what debug info is 8 generated among D compilers, written patches to DMD compiler and small updates 9 for LLDB plugin." 10 --- 11 12 Hi D community! 13 14 I'm here again, to describe what I've done during the fifth week of Symmetry 15 Autumn of Code. 16 17 ## LLVM Patches follow up 18 19 During the discussion on some patches, two other patches have been raised, 20 refactoring the usage of string utilities shared among other demanglers. 21 22 - https://reviews.llvm.org/D111948 23 - https://reviews.llvm.org/D111947 24 25 ## Second milestone kickoff 26 27 This week I started working on the second milestone, mostly covering DWARF 28 issues that I discovered. The initial idea is to research a bit about what 29 debug information is provided by each compiler and understand what can be done, 30 not only on the LLDB side but also improve information generated by the 31 compilers. 32 33 During this week I also took a look at the DWARF5 standard to understand what 34 to improve. I discovered very interesting tags that can help generalize the 35 arrays and strings interaction with the debug info. 36 37 To give a bit of context, and more deeply into the DWARF standard, 38 `DW_TAG_array_type` exists to represent array types. Similarly, there is also a 39 tag to specifically represent string types. These tags can be used with 40 `DW_TAG_subrange_type` to represent a so-called "slice" and attributes like 41 `DW_AT_count` or `DW_AT_upper_bound` can be used to represent the slice length. 42 Interestingly those attributes can refer to runtime variables and therefore 43 create debug information for a "dynamic array". I checked other compilers and 44 only C VLAs are using it. 45 46 I wrote a document describing some of the issues and comparing the DWARF 47 capabilities of the 3 most known D compilers. You can read it 48 [here](../../public/assets/posts/d-saoc-2021-05/dwarf-d-issues.md). 49 50 Some of those issues I managed to fix in the compiler backend, others I filed a 51 bug. Here is a list of patches and bug reports I created: 52 53 - https://github.com/dlang/dmd/pull/13196 54 - https://issues.dlang.org/show_bug.cgi?id=22423 55 - https://github.com/dlang/dmd/pull/13200 56 - https://issues.dlang.org/show_bug.cgi?id=22426 57 - https://github.com/dlang/dmd/pull/13202 58 - https://github.com/dlang/dmd/pull/13204 59 - https://bugs.llvm.org/show_bug.cgi?id=52223 60 61 I have an upcoming patch to the DMD backend that I'm currently working on to 62 refactor some of the DMD DWARF generator, specifically to the abbreviation 63 code. My motivation for the refactor is the fact that I spent a lot of time 64 looking into the backend codebase, implementing PR #13202. Later I realized, 65 when looking into the DWARF standard, that DWARF abbreviations are all LEB128 66 encoded and the code is not respecting that. I believe some of the errors 67 produced by the compiler is due to that. 68 69 ## LLVM Plugin 70 71 To have pretty-printing capabilities I will need to either implement some of 72 those missing DWARF tags or/and write an LLDB language plugin. The last bug 73 report on the list above triggers a discussion in that regard. Very soon I'm 74 going to write a thread on the LLVM mailing list describing the goals of the 75 plugin and discuss the possibility of upstreaming it, however, I'm not too 76 confident that will happen, because Rust among other language plugins being 77 removed from the upstream for "lacking maintainability". 78 79 I already started working on some D integration specifically on the LLDB side, 80 although I haven't pushed any of this code, since some stuff is still janky 81 experiments and not properly split up. 82 83 ## What is next? 84 85 Next week, now that I have some scope about DWARF, I'm going to tackle majorly 86 on the LLDB integration, since that is what the milestone is focused on. I'm 87 going to clean up the idea I have of the language plugin and hopefully show 88 some interesting practical results. 89 90 You can also read this on the D programming language forum, 91 [here](https://firstname.lastname@example.org), 92 and discuss there. 93 94 Read about the [previous week](../d-saoc-2021-04/) and [next 95 week](../d-saoc-2021-06/).