This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Improve function caller error message
ClosedPublic

Authored by JDevlieghere on May 25 2023, 2:07 PM.

Details

Summary

When trying to run an expression after a process has existed, you currently are shown the following error message:

(lldb) p strlen("")
error: Can't make a function caller while the process is running

This error is wrong and pretty uninformative. After this patch, the following error message is shown:

(lldb) p strlen("")
error: unable to evaluate expression while the process is exited: the process must be stopped because the expression might requires allocating memory.

rdar://109731325

Diff Detail

Event Timeline

JDevlieghere created this revision.May 25 2023, 2:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 25 2023, 2:07 PM
JDevlieghere requested review of this revision.May 25 2023, 2:07 PM
bulbazord requested changes to this revision.May 25 2023, 2:24 PM

I think it's good to improve the error messaging but I think we can probably do better. "Function caller" is specific to the internals of LLDB and isn't really meaningful for many users. It's also somewhat confusing from a user's perspective when the expression you're running isn't calling a function. For example:

alex@alangford build % ./bin/lldb ~/tmp/foo
(lldb) target create "/Users/alex/tmp/foo"
Current executable set to '/Users/alex/tmp/foo' (arm64).
(lldb) b main
Breakpoint 1: where = foo`main + 28 at foo.c:6:7, address = 0x0000000100003f68
(lldb) r
Process 44467 launched: '/Users/alex/tmp/foo' (arm64)
Process 44467 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100003f68 foo`main at foo.c:6:7
   1    #include <stdio.h>
   2
   3    int g_foo = 5;
   4
   5    int main() {
-> 6      int val = 7;
   7      printf("Hello World!: %d\n", val);
   8      return 0;
   9    }
(lldb) c
Process 44467 resuming
Hello World!: 7
Process 44467 exited with status = 0 (0x00000000)
(lldb) p val
error: Can't make a function caller while the process is running

If I were an end user who didn't know much about LLDB, I would think "I'm trying to print a variable, what's this about a function?" and "Why is memory allocation involved?". I would suggest changing the error message to something like: "Unable to evaluate expression while the process is $STATE: the process must be running and stopped to evaluate this expression".

What do you think?

This revision now requires changes to proceed.May 25 2023, 2:24 PM

I think it's good to improve the error messaging but I think we can probably do better. "Function caller" is specific to the internals of LLDB and isn't really meaningful for many users. It's also somewhat confusing from a user's perspective when the expression you're running isn't calling a function. For example:

alex@alangford build % ./bin/lldb ~/tmp/foo
(lldb) target create "/Users/alex/tmp/foo"
Current executable set to '/Users/alex/tmp/foo' (arm64).
(lldb) b main
Breakpoint 1: where = foo`main + 28 at foo.c:6:7, address = 0x0000000100003f68
(lldb) r
Process 44467 launched: '/Users/alex/tmp/foo' (arm64)
Process 44467 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100003f68 foo`main at foo.c:6:7
   1    #include <stdio.h>
   2
   3    int g_foo = 5;
   4
   5    int main() {
-> 6      int val = 7;
   7      printf("Hello World!: %d\n", val);
   8      return 0;
   9    }
(lldb) c
Process 44467 resuming
Hello World!: 7
Process 44467 exited with status = 0 (0x00000000)
(lldb) p val
error: Can't make a function caller while the process is running

If I were an end user who didn't know much about LLDB, I would think "I'm trying to print a variable, what's this about a function?" and "Why is memory allocation involved?". I would suggest changing the error message to something like: "Unable to evaluate expression while the process is $STATE: the process must be running and stopped to evaluate this expression".

What do you think?

I do agree on rephrasing the error message to be more user-friendly. I'd also assume that if the process has exited, may be dwim-print would do target variable instead of evaluating an expression, am I right @kastiglione ?

I think it's good to improve the error messaging but I think we can probably do better. "Function caller" is specific to the internals of LLDB and isn't really meaningful for many users. It's also somewhat confusing from a user's perspective when the expression you're running isn't calling a function.

If I were an end user who didn't know much about LLDB, I would think "I'm trying to print a variable, what's this about a function?" and "Why is memory allocation involved?". I would suggest changing the error message to something like: "Unable to evaluate expression while the process is $STATE: the process must be running and stopped to evaluate this expression".

What do you think?

I very much agree that error messages should first and foremost be helpful to our users. In this particular patch, we have two places where we emit this error. In UtilityFunction::MakeFunctionCaller I believe the current error is totally appropriate. That doesn't mean that I think it should be shown to the user as such. I didn't look at how this function is called, but if it trips, I would like to see an error along the lines of:

error: Couldn't run utility function. Can't make a function caller while the process is stopped: the process must be stopped to allocate memory.

On the other hand, in UserExpression::Evaluate I think it's totally appropriate to rephrase this, but at the same time I don't think we need to dumb this down.

error: Unable to evaluate expression while the process is $STATE: the process must be stopped because the expression might requires allocating memory.

I'll update the error messages accordingly.

Rephrase error message for UserExpression::Evaluate

JDevlieghere edited the summary of this revision. (Show Details)May 25 2023, 4:18 PM
JDevlieghere added inline comments.
lldb/source/Expression/UserExpression.cpp
211

This is intentionally lowercase to match the other error messages coming from UserExpression::Evaluate

bulbazord accepted this revision.May 25 2023, 4:52 PM

I think it's good to improve the error messaging but I think we can probably do better. "Function caller" is specific to the internals of LLDB and isn't really meaningful for many users. It's also somewhat confusing from a user's perspective when the expression you're running isn't calling a function.

If I were an end user who didn't know much about LLDB, I would think "I'm trying to print a variable, what's this about a function?" and "Why is memory allocation involved?". I would suggest changing the error message to something like: "Unable to evaluate expression while the process is $STATE: the process must be running and stopped to evaluate this expression".

What do you think?

I very much agree that error messages should first and foremost be helpful to our users. In this particular patch, we have two places where we emit this error. In UtilityFunction::MakeFunctionCaller I believe the current error is totally appropriate. That doesn't mean that I think it should be shown to the user as such. I didn't look at how this function is called, but if it trips, I would like to see an error along the lines of:

error: Couldn't run utility function. Can't make a function caller while the process is stopped: the process must be stopped to allocate memory.

On the other hand, in UserExpression::Evaluate I think it's totally appropriate to rephrase this, but at the same time I don't think we need to dumb this down.

error: Unable to evaluate expression while the process is $STATE: the process must be stopped because the expression might requires allocating memory.

I'll update the error messages accordingly.

This makes sense to me. I don't want to dumb things down per-se, but now that I look back at my suggestion it may have been too simplistic. I think the message you've written is an excellent. Thank you for working on this.

lldb/source/Expression/UserExpression.cpp
207–208
lldb/source/Expression/UtilityFunction.cpp
68–69
This revision is now accepted and ready to land.May 25 2023, 4:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2023, 8:50 AM