ROV error handling improvements
diff --git a/src/packages/xdc/rov/Model.xs b/src/packages/xdc/rov/Model.xs
index 4d63a78..8f09ad4 100644
--- a/src/packages/xdc/rov/Model.xs
+++ b/src/packages/xdc/rov/Model.xs
@@ -635,7 +635,13 @@
for (var k = 0; k < list.length; k++) {
var modCaps = {};
if (xdc.findFile(list[k]) != null) {
- modCaps = xdc.loadCapsule(list[k]);
+ try {
+ modCaps = xdc.loadCapsule(list[k]);
+ }
+ catch (e) {
+ throw new Error("Error in " + xdc.findFile(list[k])
+ + ": " + e);
+ }
}
else {
/* ignore missing capsules; proceed with what's possible */
diff --git a/src/packages/xdc/rov/Program.xdc b/src/packages/xdc/rov/Program.xdc
index 3fd5fc8..27ae8ae 100644
--- a/src/packages/xdc/rov/Program.xdc
+++ b/src/packages/xdc/rov/Program.xdc
@@ -354,6 +354,8 @@
* By default, only one instance of the specified type will be fetched
* from the address.
*
+ * If the type `typename` is not found, an exception is raised.
+ *
* @param(addr) Address of the C object
* @param(typeName) Name of the C type read from the address
* @param(count) Number of C objects read from the address
@@ -388,7 +390,7 @@
* by the supplied pointer variable.
*
* This API first checks if there is such a variable, and if it is of a
- * pointer type. If any of these checks fails, 'null' is returned.
+ * pointer type. If any of these checks fails, an exception is raised.
* Otherwise, the pointer variable is dereferenced, and the memory content
* is interpreted as a pointed-to type.
*/
@@ -424,6 +426,7 @@
* @param(enc) one of the following Dwarf encodings (DW_AT_encoding)
* 0x01 DW_ATE_address
* 0x02 DW_ATE_boolean
+ * 0x04 DW_ATE_float
* 0x05 DW_ATE_signed
* 0x06 DW_ATE_signed_char
* 0x07 DW_ATE_unsigned
@@ -431,7 +434,6 @@
*
* The following encodings are not supported
* 0x03 DW_ATE_complex_float
- * 0x04 DW_ATE_float
* 0x09 DW_ATE_imaginary_float
* 0x0a DW_ATE_packed_decimal
* 0x0b DW_ATE_numeric_string
@@ -514,8 +516,9 @@
/*!
* ======== lookupType ========
- * Creates a type specification from the Dwarf data. Returns null if the
- * type doesn't exist.
+ * Creates a type specification from the Dwarf data.
+ *
+ * Returns null if the type doesn't exist.
*
* @param(type) type name
*/
@@ -525,6 +528,8 @@
* ======== lookupTypeByVariable ========
* Creates a type specification from the Dwarf data for a variable.
*
+ * Returns null if the variable cannot be found.
+ *
* @param(varName) variable name
*/
Any lookupTypeByVariable(String varName);
diff --git a/src/packages/xdc/rov/Program.xs b/src/packages/xdc/rov/Program.xs
index ceee213..d7d5891 100644
--- a/src/packages/xdc/rov/Program.xs
+++ b/src/packages/xdc/rov/Program.xs
@@ -109,8 +109,8 @@
}
/* Throw an error if the module does not support the tab */
- if ((mod.viewInfo == null) ||
- !(tabName in mod.viewInfo.viewMap)) {
+ if (mod.viewInfo == null ||
+ mod.viewInfo.viewMap[tabName] == null) {
throw (new Error("Tab " + tabName + " not in module " + modName));
}
return String(mod.viewInfo.viewMap[tabName].type);
@@ -1109,11 +1109,14 @@
{
var javaType = Program.ofReader.getPtrType(varName);
if (javaType == null) {
- throw new Error("'" + varName + "' is not found, or its type is "
- + "not a pointer type.");
+ throw new Error("'" + varName + "' is not a global variable, or its "
+ + "type is not a pointer type.");
}
var typespec = _convertType(javaType);
var addr = Program.lookupSymbolValue(varName);
+ if (addr == -1) {
+ throw new Error("Cannot determine the address for '" + varName + "'.");
+ }
var ptrSize = Model.$private.recap.build.target.stdTypes.t_Ptr.size;
var ptdLocation = readMemory(addr, ptrSize, 1);
var newObj = {};
@@ -1156,9 +1159,13 @@
{
var typespec = Program.lookupTypeByVariable(varName);
if (typespec == null) {
- throw new Error("Variable " + varName + " can't be found");
+ throw new Error("Variable '" + varName + "' does not exists, or it is "
+ + "not a global variable.");
}
var addr = Program.lookupSymbolValue(varName);
+ if (addr == -1) {
+ throw new Error("Cannot determine the address for '" + varName + "'.");
+ }
var newObj = {};
Program.createObject(addr, typespec, newObj, "top");
return (newObj["top"]);
@@ -1327,7 +1334,7 @@
{
var javaType = Program.ofReader.getTypeByVariable(name);
if (javaType == null) {
- throw new Error("The variable '" + name + "' can't be found.");
+ return (null);
}
var jsType = _convertType(javaType);
return (jsType);