Skip to content

Commit

Permalink
Limited max number of table rows allowed.
Browse files Browse the repository at this point in the history
  • Loading branch information
gzachos committed Feb 1, 2021
1 parent b669dae commit 136b740
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions mars/tools/StackVisualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public class StackVisualizer extends AbstractMarsToolAndApplication {
/** Current number of table columns. */
private int numberOfColumns = colNamesWhenDataPerByte.length;
/** Current number of table rows. (-1) before table initialization. */
private int numberOfRows = -1;
private int numberOfRows = 0;
/** Offset of frame name ("Call Layout") column from table end. */
private final int frameNameColOffsetFromEnd = 0;
/** Offset of stored register column from table end. */
Expand Down Expand Up @@ -641,14 +641,26 @@ private void processStackMemoryUpdate(MemoryAccessNotice notice) {
/**
* Adds more rows in table.
*
* @param rowNumber the number of rows to add.
* @param numRowsToAdd the number of rows to add.
*/
private void addNewTableRows(int rowNumber) {
for (int ri = 0; ri < rowNumber; ri++)
private void addNewTableRows(int numRowsToAdd) {
int remainingRowsToAdd = maxTableRowsAllowed() - numberOfRows;
if (numRowsToAdd > remainingRowsToAdd)
numRowsToAdd = remainingRowsToAdd;
for (int ri = 0; ri < numRowsToAdd; ri++)
tableModel.addRow(new Object[numberOfColumns]);
numberOfRows = tableModel.getRowCount();
getStackData();
}


/**
* @return the maximum allowed number of table rows.
* Matches the number of words in the stack segment.
*/
private int maxTableRowsAllowed() {
return (Memory.stackBaseAddress - Memory.stackLimitAddress) / WORD_LENGTH_BYTES;
}


/**
Expand All @@ -658,15 +670,16 @@ private void addNewTableRows(int rowNumber) {
*/
private int getTableRowIndex(int memAddress) throws SVException {
if (!isStackSegAddress(memAddress)) {
throw new SVException("An address not in the stack segment was provided");
throw new SVException("An address not in the stack segment was provided (" + formatAddress(memAddress) + ")");
}
int rowIndex = (maxSpValueWordAligned - alignToCurrentWordBoundary(memAddress)) / WORD_LENGTH_BYTES;
if (rowIndex >= numberOfRows) {
addNewTableRows(rowIndex - numberOfRows + 10);
table.repaint();
}
if (rowIndex < 0) { // Higher address than $sp value at program start
throw new SVException("Addresses higher than " + formatAddress(maxSpValueWordAligned) + " are not currently supported");
throw new SVException("Addresses higher than " + formatAddress(maxSpValueWordAligned) +
" are not currently supported (" + formatAddress(memAddress) + ")");
}
return rowIndex;
}
Expand All @@ -679,7 +692,7 @@ private int getTableRowIndex(int memAddress) throws SVException {
*/
private int getTableColumnIndex(int memAddress) throws SVException {
if (!isStackSegAddress(memAddress))
throw new SVException("An address not in the stack segment was provided");
throw new SVException("An address not in the stack segment was provided (" + formatAddress(memAddress) + ")");
return LAST_BYTE_COLUMN - (memAddress % WORD_LENGTH_BYTES);
}

Expand All @@ -688,7 +701,13 @@ private int getTableColumnIndex(int memAddress) throws SVException {
* @return true if {@code memAddress} is in stack segment; else false.
*/
private boolean isStackSegAddress(int memAddress) {
return (memAddress >= Memory.stackLimitAddress && memAddress <= Memory.stackBaseAddress);
/*
* In default memory configuration .stackLimitAddress is address 0x7fbffffc instead of 0x10040000
* mentioned in "MIPS Memory Configuration" window.
* TODO Fix check for Default memory configuration? In this case addAsObserver() and maxTableRowsAllowed()
* will need to be fixed too.
*/
return (memAddress > Memory.stackLimitAddress && memAddress <= Memory.stackBaseAddress);
}


Expand Down

0 comments on commit 136b740

Please sign in to comment.