Search code examples
syntaxmacrosmultilinelldb

How to write a multi line macro in ~/.lldbinit?


I want to write this macro in ~/.lldbinit:

command regex pxml 's/(.+)/p xmlElemDump(stdout, %1, xmlDocGetRootElement(%1))/' -h "Dump the contents of an XML tree."

But it is too long and I want to break it into multi lines like this:

command regex pxml
    's/(.+)/p xmlElemDump(stdout, %1, xmlDocGetRootElement(%1))/'
    -h "Dump the contents of an XML tree."

or

command regex pxml\
    's/(.+)/p xmlElemDump(stdout, %1, xmlDocGetRootElement(%1))/'\
    -h "Dump the contents of an XML tree."

Unfortunately both of them cause this error:

Enter one of more sed substitution commands in the form: 's/<regex>/<subst>/'.
Terminate the substitution list with an empty line.

How can I break the macro into multi lines?


Solution

  • lldb doesn't have a continuation character. That would be tricky in some of the free-form commands, particularly the "print" command. But would be useful in these cases. Feel free to file a bug requesting this with the lldb/llvm bug tracker: https://llvm.org/bugs/.

    In most cases where a command has a few options, then takes a set of inputs, the command can enter a little mini-editor for the set of inputs. This is true for command regex. So in command line lldb, you would see:

    (lldb) command regex whatever -h "some help" -s "some syntax"
    Enter one of more sed substitution commands in the form: 's/<regex>/<subst>/'.
    Terminate the substitution list with an empty line.
    > s/First/Replacement/ 
    > s/Second/Replacement/ 
    >  
    

    The command source function that also reads the .lldbinit works by feeding the command file as a stream to the interpreter. So you need to mock up what the command line does:

    command regex whatever -h "some help" -s "some syntax"
    s/First/Replacement/
    s/Second/Replacement/
    

    That's not quite right, there has to be a blank line in the input file after the last substitution to terminate the substitutions, but I can't convince this markup to include it in the code block. But you get the idea.