1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Bug 329682 - [disassembly] Address bar does not work for symbols

This commit is contained in:
Patrick Chuong 2010-11-11 17:05:56 +00:00
parent a754d86200
commit b0f3b7b768
8 changed files with 160 additions and 83 deletions

View file

@ -8,6 +8,7 @@
* Contributors:
* Wind River Systems - initial API and implementation
* Freescale Semiconductor - refactoring
* Patrick Chuong (Texas Instruments) - Bug fix (329682)
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.disassembly.dsf;
@ -349,6 +350,20 @@ public class DisassemblyBackendCdi implements IDisassemblyBackend, IDebugEventSe
* @see org.eclipse.cdt.dsf.debug.internal.ui.disassembly.IDisassemblyBackend#gotoSymbol(java.lang.String)
*/
public void gotoSymbol(String symbol) {
final BigInteger address = evaluateSymbolAddress(symbol, false);
if (address != null) {
fCallback.asyncExec(new Runnable() {
public void run() {
fCallback.gotoAddress(address);
}});
}
}
/*
* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.ui.disassembly.dsf.IDisassemblyBackend#evaluateSymbolAddress(java.lang.String, boolean)
*/
public BigInteger evaluateSymbolAddress(String symbol, final boolean suppressError) {
if (fTargetFrameContext != null) {
try {
// This logic was lifted from CMemoryBlockRetrievalExtension.getExtendedMemoryBlock(String, Object)
@ -368,11 +383,7 @@ public class DisassemblyBackendCdi implements IDisassemblyBackend, IDebugEventSe
String addressStr = cstackFrame.evaluateExpressionToString(expr);
if (addressStr != null) {
try {
final BigInteger address = (addressStr.startsWith("0x")) ? new BigInteger(addressStr.substring(2), 16) : new BigInteger(addressStr); //$NON-NLS-1$
fCallback.asyncExec(new Runnable() {
public void run() {
fCallback.gotoAddress(address);
}});
return (addressStr.startsWith("0x")) ? new BigInteger(addressStr.substring(2), 16) : new BigInteger(addressStr); //$NON-NLS-1$
} catch (NumberFormatException e) {
if (i >= attempts.length) {
@ -390,24 +401,29 @@ public class DisassemblyBackendCdi implements IDisassemblyBackend, IDebugEventSe
}
}
catch (final CDIException exc) {
fCallback.asyncExec(new Runnable() {
public void run() {
ErrorDialog.openError(fCallback.getSite().getShell(),
CDebugUIMessages.getString("DisassemblyBackendCdi_Error_Dlg_Title"), //$NON-NLS-1$
null, new Status(IStatus.ERROR, CDebugUIPlugin.PLUGIN_ID, exc.getLocalizedMessage()));
}});
if (!suppressError) {
fCallback.asyncExec(new Runnable() {
public void run() {
ErrorDialog.openError(fCallback.getSite().getShell(),
CDebugUIMessages.getString("DisassemblyBackendCdi_Error_Dlg_Title"), //$NON-NLS-1$
null, new Status(IStatus.ERROR, CDebugUIPlugin.PLUGIN_ID, exc.getLocalizedMessage()));
}});
}
}
catch (final DebugException exc) {
fCallback.asyncExec(new Runnable() {
public void run() {
ErrorDialog.openError(fCallback.getSite().getShell(),
CDebugUIMessages.getString("DisassemblyBackendCdi_Error_Dlg_Title"), //$NON-NLS-1$
null, exc.getStatus());
}});
if (!suppressError) {
fCallback.asyncExec(new Runnable() {
public void run() {
ErrorDialog.openError(fCallback.getSite().getShell(),
CDebugUIMessages.getString("DisassemblyBackendCdi_Error_Dlg_Title"), //$NON-NLS-1$
null, exc.getStatus());
}});
}
}
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.dsf.debug.internal.ui.disassembly.IDisassemblyBackend#retrieveDisassembly(java.lang.String, int, java.math.BigInteger, boolean, boolean, boolean)
*/

View file

@ -8,6 +8,7 @@
* Contributors:
* Wind River Systems - initial API and implementation
* Freescale Semiconductor - refactoring
* Patrick Chuong (Texas Instruments) - Bug fix (329682)
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.disassembly.dsf;
@ -141,6 +142,15 @@ public interface IDisassemblyBackend {
Object insertSource(Position pos, BigInteger address, final String file, int lineNumber);
void gotoSymbol(String symbol);
/**
* Evaluate the symbol address.
*
* @param symbol the symbol
* @param suppressError true to suppress error dialogs
* @return the address, <code>null</code> if failed to evaluate symbol
*/
BigInteger evaluateSymbolAddress(String symbol, boolean suppressError);
/**
* Retrieves disassembly of the code generated by a source file, starting at

View file

@ -9,6 +9,7 @@
* Wind River Systems - initial API and implementation
* Freescale Semiconductor - refactoring
* Patrick Chuong (Texas Instruments) - Bug 323279
* Patrick Chuong (Texas Instruments) - Bug fix (329682)
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly;
@ -29,6 +30,7 @@ import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.IDisassemblyPartCallbac
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants;
import org.eclipse.cdt.dsf.concurrent.Query;
import org.eclipse.cdt.dsf.datamodel.DMContexts;
import org.eclipse.cdt.dsf.datamodel.IDMContext;
@ -61,6 +63,7 @@ import org.eclipse.cdt.dsf.service.DsfSession.SessionEndedListener;
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Position;
@ -861,57 +864,102 @@ public class DisassemblyBackendDsf implements IDisassemblyBackend, SessionEndedL
* @see org.eclipse.cdt.debug.internal.ui.disassembly.dsf.IDisassemblyBackend#gotoSymbol(java.lang.String)
*/
public void gotoSymbol(final String symbol) {
final DsfExecutor executor= getSession().getExecutor();
executor.execute(new DsfRunnable() {
public void run() {
final IExpressions expressions= getService(IExpressions.class);
if (expressions == null) {
return;
evaluateSymbolAddress(symbol, false, new DataRequestMonitor<BigInteger>(getSession().getExecutor(), null) {
@Override
protected void handleSuccess() {
final BigInteger address = getData();
if (address != null) {
fCallback.asyncExec(new Runnable() {
public void run() {
fCallback.gotoAddress(address);
}});
}
final IExpressionDMContext exprDmc= expressions.createExpression(fTargetContext, symbol);
// first, try to get l-value address
expressions.getExpressionAddressData(exprDmc, new DataRequestMonitor<IExpressionDMAddress>(executor, null) {
}
});
}
/*
* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.ui.disassembly.dsf.IDisassemblyBackend#evaluateSymbolAddress(java.lang.String, boolean)
*/
public BigInteger evaluateSymbolAddress(final String symbol, final boolean suppressError) {
Query<BigInteger> query = new Query<BigInteger>() {
@Override
protected void execute(DataRequestMonitor<BigInteger> rm) {
evaluateSymbolAddress(symbol, suppressError, rm);
}
};
getSession().getExecutor().execute(query);
try {
return query.get();
} catch (Exception e) {
return null;
}
}
private void evaluateSymbolAddress(final String symbol, final boolean suppressError, final DataRequestMonitor<BigInteger> rm) {
final IExpressions expressions= getService(IExpressions.class);
if (expressions == null) {
rm.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, IDsfStatusConstants.REQUEST_FAILED, "", null)); //$NON-NLS-1$
rm.done();
return;
}
final IExpressionDMContext exprDmc= expressions.createExpression(fTargetContext, symbol);
// first, try to get l-value address
expressions.getExpressionAddressData(exprDmc, new DataRequestMonitor<IExpressionDMAddress>(getSession().getExecutor(), null) {
@Override
protected void handleSuccess() {
IExpressionDMAddress data = getData();
IAddress address = data.getAddress();
rm.setData(address.getValue());
rm.done();
}
@Override
protected void handleError() {
// not an l-value, evaluate expression
final FormattedValueDMContext valueDmc= expressions.getFormattedValueContext(exprDmc, IFormattedValues.HEX_FORMAT);
expressions.getFormattedExpressionValue(valueDmc, new DataRequestMonitor<FormattedValueDMData>(getSession().getExecutor(), null) {
@Override
protected void handleSuccess() {
IExpressionDMAddress data = getData();
final IAddress address = data.getAddress();
if (address != null) {
fCallback.asyncExec(new Runnable() {
public void run() {
fCallback.gotoAddress(address.getValue());
}});
FormattedValueDMData data= getData();
String value= data.getFormattedValue();
BigInteger address= null;
try {
address = DisassemblyUtils.decodeAddress(value);
} catch (final Exception e) {
// "value" can be empty i.e *fooX, where fooX is a variable.
// Not sure if this is a bug or not. So, fail the request instead.
rm.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, IDsfStatusConstants.REQUEST_FAILED, "", null)); //$NON-NLS-1$
if (!suppressError) {
fCallback.asyncExec(new Runnable() {
public void run() {
ErrorDialog.openError(fCallback.getSite().getShell(), "Error", null, //$NON-NLS-1$
new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, IDsfStatusConstants.REQUEST_FAILED,
DisassemblyMessages.Disassembly_log_error_expression_eval + " (" + e.getMessage() + ")", null)); //$NON-NLS-1$ //$NON-NLS-2$
}});
}
}
rm.setData(address);
rm.done();
}
@Override
protected void handleError() {
// not an l-value, evaluate expression
final FormattedValueDMContext valueDmc= expressions.getFormattedValueContext(exprDmc, IFormattedValues.HEX_FORMAT);
expressions.getFormattedExpressionValue(valueDmc, new DataRequestMonitor<FormattedValueDMData>(executor, null) {
@Override
protected void handleSuccess() {
FormattedValueDMData data= getData();
final String value= data.getFormattedValue();
final BigInteger address= DisassemblyUtils.decodeAddress(value);
if (address != null) {
fCallback.asyncExec(new Runnable() {
public void run() {
fCallback.gotoAddress(address);
}});
}
}
@Override
protected void handleError() {
fCallback.asyncExec(new Runnable() {
public void run() {
ErrorDialog.openError(fCallback.getSite().getShell(), "Error", null, getStatus()); //$NON-NLS-1$
}});
}
});
if (!suppressError) {
fCallback.asyncExec(new Runnable() {
public void run() {
ErrorDialog.openError(fCallback.getSite().getShell(), "Error", null, getStatus()); //$NON-NLS-1$
}});
}
rm.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, IDsfStatusConstants.REQUEST_FAILED, "", null)); //$NON-NLS-1$
rm.done();
}
});
}});
}
});
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.ui.disassembly.dsf.IDisassemblyBackend#retrieveDisassembly(java.lang.String, int, java.math.BigInteger, boolean, boolean, boolean)
*/

View file

@ -8,6 +8,7 @@
* Contributors:
* Wind River Systems - initial API and implementation
* Patrick Chuong (Texas Instruments) - Bug fix (326670)
* Patrick Chuong (Texas Instruments) - Bug fix (329682)
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly;
@ -46,8 +47,8 @@ public final class DisassemblyMessages extends NLS {
public static String Disassembly_action_TrackExpression_label;
public static String Disassembly_GotoAddressDialog_title;
public static String Disassembly_GotoAddressDialog_label;
public static String Disassembly_GotoAddressDialog_error_invalid_address;
public static String Disassembly_message_notConnected;
public static String Disassembly_log_error_expression_eval;
public static String Disassembly_log_error_locateFile;
public static String Disassembly_log_error_readFile;
public static String DisassemblyPreferencePage_addressFormatTooltip;

View file

@ -8,6 +8,7 @@
# Contributors:
# Wind River Systems - initial API and implementation
# Patrick Chuong (Texas Instruments) - Bug fix (326670)
# Patrick Chuong (Texas Instruments) - Bug fix (329682)
##########################################################################
Disassembly_action_ShowAddresses_label=Show Addresses
@ -29,7 +30,6 @@ Disassembly_action_TrackExpression_label=Track Expression
Disassembly_GotoAddressDialog_title=Go to Address
Disassembly_GotoAddressDialog_label=Address expression:
Disassembly_GotoAddressDialog_error_invalid_address=Invalid address
Disassembly_GotoLocation_initial_text=Enter location here
Disassembly_GotoLocation_warning=Specified location is invalid
@ -39,6 +39,7 @@ Disassembly_Error_Dialog_ok_button=OK
Disassembly_message_notConnected=No debug context
Disassembly_log_error_expression_eval=Expression does not evaluate to an address
Disassembly_log_error_locateFile=Unable to locate file:\
Disassembly_log_error_readFile=Cannot read source file:\

View file

@ -8,6 +8,7 @@
* Contributors:
* Wind River Systems - initial API and implementation
* Patrick Chuong (Texas Instruments) - Bug fix (326670)
* Patrick Chuong (Texas Instruments) - Bug fix (329682)
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly;
@ -23,13 +24,11 @@ import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.StringTokenizer;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.AddressRangePosition;
import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.DisassemblyPosition;
import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.DisassemblyUtils;
import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.ErrorPosition;
import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.IDisassemblyBackend;
import org.eclipse.cdt.debug.internal.ui.disassembly.dsf.IDisassemblyDocument;
@ -1481,6 +1480,7 @@ public abstract class DisassemblyPart extends WorkbenchPart implements IDisassem
if (fUpdatePending) {
fUpdatePending = false;
updateVisibleArea();
fPCLastAddress = getTopAddress();
}
}
});
@ -2122,7 +2122,7 @@ public abstract class DisassemblyPart extends WorkbenchPart implements IDisassem
if (!isSyncWithActiveDebugContext()) {
if (isTrackExpression()) {
if (!DisassemblyMessages.Disassembly_GotoLocation_initial_text.equals(fPCLastLocationTxt))
fPCLastAddress = eval(fPCLastLocationTxt);
fPCLastAddress = eval(fPCLastLocationTxt, true);
}
if (fPCLastAddress != PC_UNKNOWN) {
address = fPCLastAddress;
@ -2130,7 +2130,9 @@ public abstract class DisassemblyPart extends WorkbenchPart implements IDisassem
fPCLastAddress = address;
}
frame = -2; // clear the annotation
// need to get the frame address when the view first started.
if (fPCLastAddress != PC_UNKNOWN)
frame = -2; // clear the annotation
} else {
fPCLastAddress = address;
}
@ -2960,19 +2962,13 @@ public abstract class DisassemblyPart extends WorkbenchPart implements IDisassem
return ""; //$NON-NLS-1$
}
public BigInteger eval(String expr) {
String location = evaluateExpression(expr);
if (location != null) {
StringTokenizer st = new StringTokenizer(location);
if (st.hasMoreTokens()) {
try {
return DisassemblyUtils.decodeAddress(st.nextToken());
} catch (Exception e) {
logWarning("Failed to evaluate expression " + expr, e); //$NON-NLS-1$
}
}
}
return PC_UNKNOWN;
public BigInteger eval(String expr, boolean suppressError) {
if (fBackend != null) {
BigInteger address = fBackend.evaluateSymbolAddress(expr, suppressError);
if (address != null)
return address;
}
return PC_UNKNOWN;
}
protected boolean isTrackExpression() {

View file

@ -7,6 +7,7 @@
*
* Contributors:
* Texas Instruments - Initial API and implementation
* Patrick Chuong (Texas Instruments) - Bug fix (329682)
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly.actions;
@ -46,6 +47,7 @@ public class AddressBarContributionItem extends ContributionItem {
private ToolItem item;
private int width;
private String initialText;
private String lastText;
private Image warningImage = null;
private Label warningLabel = null;
private String warningText = null;
@ -80,6 +82,7 @@ public class AddressBarContributionItem extends ContributionItem {
String warningText) {
this.width = width;
this.initialText = initialText;
this.lastText = initialText;
this.warningText = warningText;
fill(parent, 0);
@ -237,8 +240,10 @@ public class AddressBarContributionItem extends ContributionItem {
((JumpToAddressAction)action).deactivateDisassemblyContext();
// end 297387
lastText = addressBox.getText();
// Erase the guide text when the focus is gained.
if (addressBox.getText().trim().equals(initialText))
if (lastText.trim().equals(initialText))
addressBox.setText(""); //$NON-NLS-1$
// [nmehregani]: Support Ctrl+C in address bar
@ -251,10 +256,10 @@ public class AddressBarContributionItem extends ContributionItem {
((JumpToAddressAction)action).activateDisassemblyContext();
// end 297387
// Re-insert the guide text when the focus is lost and the text
// Re-insert the last text when the focus is lost and the text
// field is empty.
if (addressBox.getText().trim().length() == 0)
addressBox.setText(initialText);
addressBox.setText(lastText);
// [nmehregani]: Support Ctrl+C in address bar
addressBox.removeKeyListener(keyListener);

View file

@ -8,6 +8,7 @@
* Contributors:
* Texas Instruments[nmehregani] - initial API and implementation
* Patrick Chuong (Texas Instruments) - Bug fix (326670)
* Patrick Chuong (Texas Instruments) - Bug fix (329682)
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly.actions;
@ -42,10 +43,9 @@ public class JumpToAddressAction extends Action {
return;
}
BigInteger address = fDisassemblyPart.eval(locationTxt);
BigInteger address = fDisassemblyPart.eval(locationTxt, false);
if (address.compareTo(BigInteger.ZERO) < 0) {
addressBar.setWarningIconVisible(true);
fDisassemblyPart.generateErrorDialog(DisassemblyMessages.Disassembly_GotoAddressDialog_error_invalid_address);
} else {
fDisassemblyPart.gotoLocationByUser(address, locationTxt);
addressBar.setWarningIconVisible(false);