Describe 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:
createLabel(currentAddress, "test", True)createLabel(currentAddress, "next", True)Expected behavior
Make the new label the primary label
Environment (please complete the following information):
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.
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!
Thanks for the fast response.
Actually, I have another question, how do I make a label that already exists the new primary label, or function name. I get
ghidra.util.exception.DuplicateNameException: ... A symbol named "test" already exists at this address!
when I try to use setName. There must be a way since I can just click the box when editing the label manually. Do I have do delete the label first? @GhidraKnight
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.
Thanks again, works great! In javadocs, I noticed "that" should be "than" below:
public class SetLabelPrimaryCmd
extends java.lang.Object
implements Command
Command to make a label the primary label at an address. Only really makes sense if there is more that one label at the address - otherwise the label will already be primary.
Most helpful comment
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.