This is an archive of the discontinued LLVM Phabricator instance.

Expose top-level expressions via the LLDB command line and public API
Needs RevisionPublic

Authored by spyffe on Mar 22 2016, 5:36 PM.

Details

Summary

A recent series of commits have added the infrastructure to support top-level expressions in LLDB; this patch exposes and tests the functionality.

It is exposed via a new argument to expression, -p / --top-level. When this command is provided, the expression is compiled and injected into the process via the JIT, and the resultant declarations and types are stored. However, only static initializers are run; there is no concept of a top-level expression. The intent is that later code can use the variables, functions, and classes defined by these expressions.

I've also added a testcase that verifies that top-level code acts exactly the same way as if it were written in a source file. Complicated inline functions are also included. This testcase requires a clang patch (fixing some missing cases in ASTImporter) to work correctly, but it should give you an idea of what I expect to work.

Diff Detail

Repository
rL LLVM

Event Timeline

spyffe updated this revision to Diff 51368.Mar 22 2016, 5:36 PM
spyffe retitled this revision from to Expose top-level expressions via the LLDB command line and public API.
spyffe updated this object.
spyffe added reviewers: jingham, clayborg, ldrumm, ted.
spyffe set the repository for this revision to rL LLVM.
clayborg accepted this revision.Mar 23 2016, 9:56 AM
clayborg edited edge metadata.
This revision is now accepted and ready to land.Mar 23 2016, 9:56 AM
jingham accepted this revision.Mar 24 2016, 7:08 PM
jingham edited edge metadata.

Looks good to me too.

ldrumm edited edge metadata.Mar 29 2016, 6:46 AM

Hi Sean

Thanks for you patience - just got back from holiday. This looks good in general, but I have a few minor nitpicks that I think are worth a look.

L

include/lldb/API/SBExpressionOptions.h
118

Please make b a more descriptive name, and perhaps add documentation for these methods.

packages/Python/lldbsuite/test/expression_command/top-level/TestTopLevelExprs.py
11

os and time appear to be unused imports and may be removed

67

This parsing of expressions can be simplified to the following:

with open("test.cpp") as f:
    expressions = f.read().split("// --")

This also has the nice property of closing the file automatically.

81

I'm not sure about whether LLVM dictates a special style for Python code, but my preference would be to follow the spirit of PEP8 i.e. result_from_top_level = ..., reformat the spaces before parens for function calls, stick to 80columns etc.

If however LLDB uses some other style for Python, please ignore me :)

source/API/SBExpressionOptions.cpp
207

As above, I feel b should be renamed - perhaps top_level?

ldrumm requested changes to this revision.Mar 29 2016, 6:46 AM
ldrumm edited edge metadata.
This revision now requires changes to proceed.Mar 29 2016, 6:46 AM