How can I create a LLDB alias that evaluates its argument using `expression`
Asked Answered
C

3

6

I'm trying to create a LLDB alias that evaluates an expression using the argument (%1) to the alias. I've tried many, many different syntax combinations, but it seems like anything that uses %1 in an expression fails to parse.

(lldb) version
LLDB-112.1

This works as expected:

(lldb) expr (char*) strdup(argv[1])
(char *) $23 = 0x000000010061c090 "--calc"

When I create an alias containing %1 the example fails.

(lldb) command alias dup expr (char*) strdup(%1)
(lldb) dup argv[1]
error: expected expression
error: 1 errors parsing expression

How can I create a LLDB alias that evaluates its argument using expression?

Caslon answered 17/4, 2012 at 20:52 Comment(0)
T
4

To make arguments in expression work, use command regex instead of alias, like this:

command regex dup 's/(.+)/expr (char*) strdup(%1)/'

For more details, see this answer.

Tavarez answered 30/8, 2012 at 10:58 Comment(0)
O
0

I have played around with the %1 aliases quite a bit, no luck yet. This is the closest I can come, and it's not wonderful:

[.lldbinit]

command alias foo expr fooFunction(

Then when running the debugger, the following command will in fact call the function fooFunction with input bar:

(lldb) foo bar)

That unmatched close paren is not a typo; it needs to be there to match the open paren from the alias.

Oraleeoralia answered 16/5, 2012 at 19:54 Comment(0)
C
0

try command alias dup expr -- (char*) strdup( $1 ); then you'll see

(lldb) dup "2387987"
(const char [8]) $5 = "2387987" {
  (const char) [0] = '2'
  (const char) [1] = '3'
  (const char) [2] = '8'
  (const char) [3] = '7'
  (const char) [4] = '9'
  (const char) [5] = '8'
  (const char) [6] = '7'
  (const char) [7] = '\0'

for lldb build 153

Chemisette answered 28/6, 2012 at 4:10 Comment(1)
It looks like the $1 refers to something different than %1. Are you sure this is correct? I want the first argument to the macro, rather than the first evaluated expression output.Caslon

© 2022 - 2024 — McMap. All rights reserved.