This is an archive of the discontinued LLVM Phabricator instance.

[LLDB] OpenBSD support
ClosedPublic

Authored by kettenis on Mar 19 2017, 4:51 PM.

Details

Summary

Add basic OpenBSD support. This is enough to be able to analyze core dumps for OpenBSD/amd64, OpenBSD/arm, OpenBSD/arm64 and OpenBSD/i386.

Note that part of the changes to source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp fix a bug that probably affects other platforms as well. The GetProgramHeaderByIndex() interface use 1-based indices, but in some case when looping over the headers the, the loop starts at 0 and misses the last header. This caused problems on OpenBSD since OpenBSD core dumps have the PT_NOTE segment as the last program header.

Diff Detail

Event Timeline

kettenis created this revision.Mar 19 2017, 4:51 PM

Fantastic!

I got a substantial portion of Process Plugin to work on NetBSD, to coordinate the work feel free to join IRC #lldb at OFTC -- e.g. do not waste time on FreeBSD Process Plugin.

Demo:
http://www.netbsd.org/~kamil/lldb/hello2.txt

I'm working on on remaining few features in order to upstream them.

source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
61

Please delete __FreeBSD__ here and from the FreeBSD platform switch for __OpenBSD__, but I don't insist on doing the FreeBSD tweak within the same commit.

source/Plugins/Process/elf-core/ProcessElfCore.cpp
588

note.n_name == "OpenBSD" ?

source/Plugins/Process/elf-core/ThreadElfCore.cpp
115

I would consider to keep it sorted - after Linux.

krytarowski set the repository for this revision to rL LLVM.
krytarowski added a project: Restricted Project.
krytarowski added inline comments.Mar 19 2017, 6:54 PM
source/Host/openbsd/Host.cpp
224

Wasn't it already gone from there?

krytarowski added inline comments.Mar 19 2017, 7:11 PM
include/lldb/Host/Config.h
35

Missing in patch?

krytarowski added inline comments.Mar 19 2017, 8:00 PM
include/lldb/Host/Config.h
35

I think that Config.h should go away. It's almost empty. But it's beyond the scope of this patch.

While there I would sort this list of includes again.

include/lldb/Host/HostInfo.h
55

I would sort includes here.

krytarowski added inline comments.Mar 19 2017, 8:03 PM
source/Plugins/Platform/CMakeLists.txt
8

I would sort by subdirectory.

labath edited edge metadata.Mar 20 2017, 3:08 AM

Looks like a great start. If you want to continue and get live process debugging working as well, you should definitely sync up with kamil (i.e. don't start from ProcessFreeBSD, his process plugin should be a much better starting point).

In terms of this patch, I have a couple of comments over the supported architectures. Also, please make sure you run clang-format over your diff, as some odd formatting has crept in.

I am not going to block this change over it, but it would be great (for the sake of your own platform) if you could try to generate a tiny core file to check in, to make sure that any further lldb changes to not break you. For linux, we've gotten these down to ~30k, but we've had some problems doing the same on FreeBSD (https://reviews.llvm.org/D26617), and unfortunately I haven't yet found time to investigate this.

source/Host/openbsd/Host.cpp
224

Yep, this should be deleted completely.

source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
159

As far as I can tell, you're only adding x86_64 support, so you should probably remove the others.

source/Plugins/Process/elf-core/ThreadElfCore.cpp
118

Have you checked that the arm64 case would work here? (at least whether the register context have roughly the same layout ?)

kettenis marked 2 inline comments as done.Mar 20 2017, 4:31 AM

Will revise the diff based on your comments. Thanks!

include/lldb/Host/Config.h
35

Oops yes; missed adding a directory.

include/lldb/Host/HostInfo.h
55

Do you want me to sort the entire list?

source/Host/openbsd/Host.cpp
224

Gone.

source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
61

Will do.

159

True. I trimmed the list that FreeBSD had. My intention is to submit support for all these architectures. But I can leave the currently unsupported ones out.

source/Plugins/Process/elf-core/ProcessElfCore.cpp
588

That wouldn't work. The notes describing the registers have the thread ID attached to this name, i.e. "OpenBSD@250037". I'll need to parse that string to make core dumps of multi-threaded processes work later.

source/Plugins/Process/elf-core/ThreadElfCore.cpp
115

Will do.

118

I'm actually working on making the layout the same (OpenBSD/arm64 is still under heavy development). I'll make sure it works before this diff lands ;)

krytarowski added inline comments.Mar 20 2017, 4:47 AM
include/lldb/Host/HostInfo.h
55

Yes, here and in other places as well. We might get more targets and it's better to keep it in order.

source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
159

This is what I'm doing in NetBSD. Adding x86_64 first, i386 next and later the rest -- perhaps starting with arm 32-bit.

krytarowski edited edge metadata.Mar 20 2017, 7:23 AM
krytarowski added inline comments.Mar 20 2017, 4:03 PM
source/Plugins/Process/elf-core/ProcessElfCore.cpp
588

I would change it o string::substr to make it more clear that it's not just secure comparison of a string. A comment explaining it for those not familiar with OpenBSD internals would be nice.

krytarowski added inline comments.Mar 21 2017, 7:16 AM
source/Host/openbsd/HostInfoOpenBSD.cpp
21

The need for this has been removed in trunk.

kettenis updated this revision to Diff 92857.Mar 23 2017, 1:24 PM
kettenis marked an inline comment as done.
kettenis edited the summary of this revision. (Show Details)

New diff. This one adds support for OpenBSD/amd64, OpenBSD/arm, OpenBSD/arm64 and OpenBSD/i386. I'm holding off on resorting existing code. I'm willing to do that in a separate diff.

kettenis updated this revision to Diff 92861.Mar 23 2017, 1:53 PM

Apologies. Previous diff contained a bogus change to DYLDRendezvous.cpp and a formatting botch. Please review this updated version instead,

krytarowski added inline comments.Mar 24 2017, 4:07 AM
source/CMakeLists.txt
25

@labath are the includes for Plugins/Process/FreeBSD and Plugins/Process/FreeBSD necessary? I don't need to add Plugins/Process/NetBSD in order to make things work.

(it's not related to OpenBSD patch here)

source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.cpp
49

no DBG regs here?

krytarowski accepted this revision.Mar 24 2017, 5:14 AM

In general it looks good.

This revision is now accepted and ready to land.Mar 24 2017, 5:14 AM
kettenis added inline comments.Mar 24 2017, 6:56 AM
source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.cpp
49

OpenBSD doesn't actually implement access to the debug registers.

kettenis updated this revision to Diff 92938.Mar 24 2017, 6:57 AM

Updated diff to account for the FileSpec.h move.

krytarowski added inline comments.Mar 24 2017, 7:54 AM
source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.cpp
49

Yes, I know, there are also accessors for xmm registers. So far I have not been there with NetBSD either and your code follows FreeBSD (Linux has debug registers in userdata).

Can somebody commit this diff for me?

Can somebody commit this diff for me?

Sure, I'm on it.

krytarowski closed this revision.Mar 26 2017, 8:47 AM
labath added inline comments.Mar 28 2017, 9:00 AM
source/CMakeLists.txt
25

You probably need the ProcessPosixLog file at least. However, the only thing which this affects is how you need to include them, so if you use the long Plugins/Process/POSIX/XXX path, you are fine.

As a matter of fact, we should probably use that path everywhere, and then these can go away. (future cleanup idea).