createLabel doesn't set a new label as the primary label on a function
See original GitHub issueDescribe the bug
When using the default createLabel
method exposed to the python api, it will not correctly set the new label as the primary label even if True
is passed for makePrimary
on a function. It does seem to work at any other point in the listing.
To Reproduce Steps to reproduce the issue:
-
use the cursor to select a the beginning of a function at a “FUN_***”
-
open the python console
-
type
createLabel(currentAddress, "test", True)
-
In listing, see the new label for the function name and that it is primary
-
go back to console and type
createLabel(currentAddress, "next", True)
-
In listing, see the old label is still the primary label
-
go to any other point in the function, repeat 3-5
-
see that “next” is now the primary label (expected behavior I think)
Expected behavior Make the new label the primary label
Environment (please complete the following information):
- OS: Windows 10 x64
- Java Version: openjdk 11.0.2
- Ghidra Version: 9.0 and 9.0.1
Additional context I can edit the new label I’ve created and manually change it to be the primary label by clicking the box. Maybe I’m just doing something wrong. Thanks for any help.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
There’s several ways to accomplish it via the Ghidra API. Try invoking the SetLabelPrimaryCmd. This command will handle setting a label to primary, and it handles the case where you want to change the function name.
Command command= new SetLabelPrimaryCmd( address, name, namespace ) command.applyTo( currentProgram );
The “name” parameter needs to already exist as a label/symbol.
Sorry for the confusion. This behavior is as-designed; functions are special case labels(symbols). In order to change the name of a function, you must get the function object at the current address and call setName(). Will try to update the javadoc to reflect this case.
Function fun = getFunctionAt(currentAddress) if ( fun == null ) createLabel(…) else fun.setName(…)
Thanks!