Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Libretro
SquirrelJME
Commits
795433b4
Commit
795433b4
authored
Jul 18, 2021
by
Stephanie Gawroriski
Browse files
More pickings of the call traces.
parent
9d51007d
Changes
5
Show whitespace changes
Inline
Side-by-side
modules/cldc-compact/src/main/java/cc/squirreljme/jvm/JVMFunction.java
View file @
795433b4
...
...
@@ -345,9 +345,8 @@ public final class JVMFunction
public
static
final
long
jvmSystemCall
(
short
__si
,
int
__a
,
int
__b
,
int
__c
,
int
__d
,
int
__e
,
int
__f
,
int
__g
,
int
__h
)
{
// Call pure form
return
Assembly
.
sysCallPVL
(
__si
,
__a
,
__b
,
__c
,
__d
,
__e
,
__f
,
__g
,
__h
);
Assembly
.
breakpoint
();
throw
Debugging
.
todo
();
}
}
modules/cldc-compact/src/main/java/cc/squirreljme/jvm/SystemCallError.java
View file @
795433b4
...
...
@@ -76,40 +76,21 @@ public final class SystemCallError
public
static
final
byte
NO_SUCH_CONFIG_KEY
=
-
14
;
/**
* Not used.
*
* @since 2019/05/23
*/
private
SystemCallError
()
{
}
/** Invalid memory handle kind. */
public
static
final
byte
INVALID_MEMHANDLE_KIND
=
-
15
;
/**
* Checks if an error was set, if it was an exception is thrown.
*
* @param __si The system call to check.
* @throws SystemCallException If there was an error.
* @since 2020/01/12
*/
public
static
void
checkError
(
short
__si
)
throws
SystemCallException
{
int
code
=
SystemCallError
.
getError
(
__si
);
if
(
code
!=
SystemCallError
.
NO_ERROR
)
throw
new
SystemCallException
(
__si
,
code
);
}
/** Could not flush the pipe. */
public
static
final
byte
PIPE_DESCRIPTOR_BAD_FLUSH
=
-
16
;
/**
*
Returns the error state
.
*
Not used
.
*
* @param __si The system call index.
* @return The error, 0 will be on success.
* @since 2019/05/23
*/
p
ublic
static
int
getError
(
short
__si
)
p
rivate
SystemCallError
(
)
{
return
Assembly
.
sysCallV
(
SystemCallIndex
.
ERROR_GET
,
__si
);
}
/**
...
...
modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/debug/CallTraceElement.java
View file @
795433b4
...
...
@@ -10,13 +10,6 @@
package
cc.squirreljme.runtime.cldc.debug
;
import
cc.squirreljme.jvm.Assembly
;
import
cc.squirreljme.jvm.CallStackItem
;
import
cc.squirreljme.jvm.SystemCallError
;
import
cc.squirreljme.jvm.SystemCallIndex
;
import
cc.squirreljme.jvm.mle.brackets.TracePointBracket
;
import
java.lang.ref.Reference
;
import
java.lang.ref.WeakReference
;
import
java.util.Objects
;
/**
...
...
@@ -54,14 +47,8 @@ public final class CallTraceElement
/** The task ID. */
protected
final
int
taskId
;
/** String representation. */
private
Reference
<
String
>
_string
;
/** At line form. */
private
Reference
<
String
>
_stringatl
;
/** Class header form. */
private
Reference
<
String
>
_stringclh
;
/** The native instruction type. */
protected
final
int
nativeOp
;
/** Hash code. */
private
int
_hash
;
...
...
@@ -142,6 +129,28 @@ public final class CallTraceElement
*/
public
CallTraceElement
(
String
__cl
,
String
__mn
,
String
__md
,
long
__addr
,
String
__file
,
int
__line
,
int
__jbc
,
int
__jpc
,
int
__tid
)
{
this
(
__cl
,
__mn
,
__md
,
__addr
,
__file
,
__line
,
__jbc
,
__jpc
,
__tid
,
-
1
);
}
/**
* Initializes a call trace element.
*
* @param __cl The class name.
* @param __mn The method name.
* @param __md The method descriptor.
* @param __addr The address the method executes at.
* @param __file The file.
* @param __line The line in the file.
* @param __jbc The Java byte code instruction used.
* @param __jpc The Java PC address.
* @param __tid The task ID.
* @param __nOp The native operation.
* @since 2021/01/24
*/
public
CallTraceElement
(
String
__cl
,
String
__mn
,
String
__md
,
long
__addr
,
String
__file
,
int
__line
,
int
__jbc
,
int
__jpc
,
int
__tid
,
int
__nOp
)
{
this
.
className
=
__cl
;
this
.
methodName
=
__mn
;
...
...
@@ -152,6 +161,7 @@ public final class CallTraceElement
this
.
byteCodeOp
=
__jbc
;
this
.
byteCodeAddr
=
__jpc
;
this
.
taskId
=
__tid
;
this
.
nativeOp
=
__nOp
;
}
/**
...
...
@@ -224,7 +234,8 @@ public final class CallTraceElement
this
.
line
==
o
.
line
&&
this
.
byteCodeOp
==
o
.
byteCodeOp
&&
this
.
byteCodeAddr
==
o
.
byteCodeAddr
&&
this
.
taskId
==
o
.
taskId
;
this
.
taskId
==
o
.
taskId
&&
this
.
nativeOp
==
o
.
nativeOp
;
}
/**
...
...
@@ -257,7 +268,8 @@ public final class CallTraceElement
~
this
.
line
+
~
this
.
byteCodeOp
+
~
this
.
byteCodeAddr
+
~
this
.
taskId
);
~
this
.
taskId
+
~
this
.
nativeOp
);
}
return
rv
;
}
...
...
@@ -295,6 +307,17 @@ public final class CallTraceElement
return
this
.
methodName
;
}
/**
* Returns the native operation.
*
* @return The native operation.
* @since 2021/01/24
*/
public
final
int
nativeOp
()
{
return
this
.
nativeOp
;
}
/**
* Formats the call trace element but having it only represent the method
* point without the class information.
...
...
@@ -303,11 +326,6 @@ public final class CallTraceElement
* @since 2019/05/11
*/
public
final
String
toAtLineString
()
{
Reference
<
String
>
ref
=
this
.
_stringatl
;
String
rv
;
if
(
ref
==
null
||
null
==
(
rv
=
ref
.
get
()))
{
// Get all fields to determine how to print it pretty
String
methodname
=
this
.
methodName
,
...
...
@@ -316,7 +334,8 @@ public final class CallTraceElement
int
line
=
this
.
line
;
int
jInst
=
this
.
byteCodeOp
&
0xFF
;
int
jAddr
=
this
.
byteCodeAddr
;
int
taskid
=
this
.
taskId
;
int
taskId
=
this
.
taskId
;
int
nativeOp
=
this
.
nativeOp
;
// Format it nicely
StringBuilder
sb
=
new
StringBuilder
();
...
...
@@ -333,10 +352,10 @@ public final class CallTraceElement
}
// Task ID?
if
(
task
i
d
!=
0
)
if
(
task
I
d
!=
0
)
{
sb
.
append
(
" T"
);
sb
.
append
(
task
i
d
);
sb
.
append
(
task
I
d
);
}
// Execution address
...
...
@@ -344,18 +363,18 @@ public final class CallTraceElement
{
sb
.
append
(
" @"
);
// If the address is really high then it is very likely that
// this is some RAM/ROM address rather than some easily read
// index. This makes them more readable and understandable
if
(
address
>
4096
)
{
sb
.
append
(
Long
.
toString
(
address
,
16
).
toUpperCase
());
sb
.
append
(
'h'
);
}
// Otherwise use an index
else
sb
.
append
(
address
);
// Is there a native operation?
if
(
nativeOp
>=
0
)
{
sb
.
append
(
" ^"
);
sb
.
append
(
Integer
.
toString
(
nativeOp
,
16
).
toUpperCase
());
sb
.
append
(
"h/"
);
sb
.
append
(
Integer
.
toString
(
nativeOp
,
2
).
toUpperCase
());
sb
.
append
(
'b'
);
}
// File, Line, and/or Java instruction/address
...
...
@@ -396,10 +415,7 @@ public final class CallTraceElement
sb
.
append
(
')'
);
}
this
.
_stringatl
=
new
WeakReference
<>((
rv
=
sb
.
toString
()));
}
return
rv
;
return
sb
.
toString
();
}
/**
...
...
@@ -409,11 +425,6 @@ public final class CallTraceElement
* @since 2019/05/11
*/
public
final
String
toClassHeaderString
()
{
Reference
<
String
>
ref
=
this
.
_stringclh
;
String
rv
;
if
(
ref
==
null
||
null
==
(
rv
=
ref
.
get
()))
{
// Get all fields to determine how to print it pretty
String
classname
=
this
.
className
,
...
...
@@ -434,10 +445,7 @@ public final class CallTraceElement
sb
.
append
(
')'
);
}
this
.
_stringclh
=
new
WeakReference
<>((
rv
=
sb
.
toString
()));
}
return
rv
;
return
sb
.
toString
();
}
/**
...
...
@@ -446,11 +454,6 @@ public final class CallTraceElement
*/
@Override
public
final
String
toString
()
{
Reference
<
String
>
ref
=
this
.
_string
;
String
rv
;
if
(
ref
==
null
||
null
==
(
rv
=
ref
.
get
()))
{
// Get all fields to determine how to print it pretty
String
classname
=
this
.
className
,
...
...
@@ -462,6 +465,7 @@ public final class CallTraceElement
int
jbcinst
=
this
.
byteCodeOp
&
0xFF
;
int
jbcaddr
=
this
.
byteCodeAddr
;
int
taskid
=
this
.
taskId
;
int
nativeOp
=
this
.
nativeOp
;
// Format it nicely
StringBuilder
sb
=
new
StringBuilder
();
...
...
@@ -487,18 +491,18 @@ public final class CallTraceElement
{
sb
.
append
(
" @"
);
// If the address is really high then it is very likely that
// this is some RAM/ROM address rather than some easily read
// index. This makes them more readable and understandable
if
(
address
>
4096
)
{
sb
.
append
(
Long
.
toString
(
address
,
16
).
toUpperCase
());
sb
.
append
(
'h'
);
}
// Otherwise use an index
else
sb
.
append
(
address
);
// Is there a native operation?
if
(
nativeOp
>=
0
)
{
sb
.
append
(
" ^"
);
sb
.
append
(
Integer
.
toString
(
nativeOp
,
16
).
toUpperCase
());
sb
.
append
(
"h/"
);
sb
.
append
(
Integer
.
toString
(
nativeOp
,
2
).
toUpperCase
());
sb
.
append
(
'b'
);
}
// File, Line, and/or Java instruction/address
...
...
@@ -544,130 +548,7 @@ public final class CallTraceElement
sb
.
append
(
')'
);
}
this
.
_string
=
new
WeakReference
<>((
rv
=
sb
.
toString
()));
}
return
rv
;
}
/**
* Obtains the current raw call trace which has not been resolved.
*
* @return The raw call trace.
* @since 2019/06/16
*/
@Deprecated
public
static
final
int
[]
traceRaw
()
{
// Get the call height, ignore if not supported!
int
callheight
=
Assembly
.
sysCallPV
(
SystemCallIndex
.
CALL_STACK_HEIGHT
);
if
(
callheight
<=
0
||
Assembly
.
sysCallPV
(
SystemCallIndex
.
ERROR_GET
,
SystemCallIndex
.
CALL_STACK_HEIGHT
)
!=
SystemCallError
.
NO_ERROR
)
return
new
int
[
0
];
// Remove the top-most frame because it will be this method
callheight
--;
// Get the call parameters
int
[]
rv
=
new
int
[
callheight
*
CallStackItem
.
NUM_ITEMS
];
for
(
int
z
=
0
,
base
=
0
;
z
<
callheight
;
z
++,
base
+=
CallStackItem
.
NUM_ITEMS
)
for
(
int
i
=
0
;
i
<
CallStackItem
.
NUM_ITEMS
;
i
++)
{
// Get parameter
int
vx
=
Assembly
.
sysCallPV
(
SystemCallIndex
.
CALL_STACK_ITEM
,
1
+
z
,
i
);
// Nullify unknown or invalid parameters
if
(
Assembly
.
sysCallPV
(
SystemCallIndex
.
ERROR_GET
,
SystemCallIndex
.
CALL_STACK_ITEM
)
!=
SystemCallError
.
NO_ERROR
)
vx
=
0
;
// Fill in
rv
[
base
+
i
]
=
vx
;
}
// Return the raw parameters
return
rv
;
}
/**
* Resolves the specified call trace into call trace elements.
*
* @param __trace The trace to resolve.
* @return The resolved trace.
* @throws NullPointerException On null arguments.
* @since 2019/06/16
*/
@Deprecated
public
static
final
CallTraceElement
[]
traceResolve
(
int
[]
__trace
)
throws
NullPointerException
{
if
(
__trace
==
null
)
throw
new
NullPointerException
(
"NARG"
);
// Get the call height
int
callheight
=
__trace
.
length
/
CallStackItem
.
NUM_ITEMS
;
// Process all the items
CallTraceElement
[]
rv
=
new
CallTraceElement
[
callheight
];
for
(
int
z
=
0
,
base
=
0
;
z
<
callheight
;
z
++,
base
+=
CallStackItem
.
NUM_ITEMS
)
{
// Load class name
int
xcl
=
Assembly
.
sysCallV
(
SystemCallIndex
.
LOAD_STRING
,
__trace
[
base
+
CallStackItem
.
CLASS_NAME
]);
String
scl
=
((
xcl
==
0
||
Assembly
.
sysCallV
(
SystemCallIndex
.
ERROR_GET
,
SystemCallIndex
.
LOAD_STRING
)
!=
SystemCallError
.
NO_ERROR
)
?
(
String
)
null
:
(
String
)
Assembly
.
pointerToObject
(
xcl
));
// Load method name
int
xmn
=
Assembly
.
sysCallV
(
SystemCallIndex
.
LOAD_STRING
,
__trace
[
base
+
CallStackItem
.
METHOD_NAME
]);
String
smn
=
((
xmn
==
0
||
Assembly
.
sysCallV
(
SystemCallIndex
.
ERROR_GET
,
SystemCallIndex
.
LOAD_STRING
)
!=
SystemCallError
.
NO_ERROR
)
?
(
String
)
null
:
(
String
)
Assembly
.
pointerToObject
(
xmn
));
// Load method type
int
xmt
=
Assembly
.
sysCallV
(
SystemCallIndex
.
LOAD_STRING
,
__trace
[
base
+
CallStackItem
.
METHOD_NAME
]);
String
smt
=
((
xmt
==
0
||
Assembly
.
sysCallV
(
SystemCallIndex
.
ERROR_GET
,
SystemCallIndex
.
LOAD_STRING
)
!=
SystemCallError
.
NO_ERROR
)
?
(
String
)
null
:
(
String
)
Assembly
.
pointerToObject
(
xmt
));
// Load source file
int
xsf
=
Assembly
.
sysCallV
(
SystemCallIndex
.
LOAD_STRING
,
__trace
[
base
+
CallStackItem
.
SOURCE_FILE
]);
String
ssf
=
((
xsf
==
0
||
Assembly
.
sysCallV
(
SystemCallIndex
.
ERROR_GET
,
SystemCallIndex
.
LOAD_STRING
)
!=
SystemCallError
.
NO_ERROR
)
?
(
String
)
null
:
(
String
)
Assembly
.
pointerToObject
(
xsf
));
// The PC address
int
pcaddr
=
__trace
[
base
+
CallStackItem
.
PC_ADDRESS
];
// Task ID
int
tid
=
__trace
[
base
+
CallStackItem
.
TASK_ID
];
// Build elements
rv
[
z
]
=
new
CallTraceElement
(
scl
,
smn
,
smt
,
(
pcaddr
==
0
?
-
1
:
pcaddr
),
ssf
,
__trace
[
base
+
CallStackItem
.
SOURCE_LINE
],
__trace
[
base
+
CallStackItem
.
JAVA_OPERATION
],
__trace
[
base
+
CallStackItem
.
JAVA_PC_ADDRESS
],
tid
);
}
// Use the resolved form
return
rv
;
return
sb
.
toString
();
}
}
modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/debug/CallTraceUtils.java
View file @
795433b4
...
...
@@ -106,6 +106,7 @@ public final class CallTraceUtils
// We do not want any IOExceptions to cause stack trace printing to
// fail, since this could potentially lead to a very nasty infinite
// exception loop
int
lockStep
=
0
;
try
{
// If there is no actual trace then just print that this is the
...
...
@@ -120,6 +121,9 @@ public final class CallTraceUtils
CallTraceUtils
.
__appendIndent
(
__out
,
__indentLevel
);
__out
.
append
(
"EXCEPTION "
);
// Count step
lockStep
++;
// And that message could be blank!
if
(
__message
!=
null
)
__out
.
append
(
__message
);
...
...
@@ -128,6 +132,9 @@ public final class CallTraceUtils
// Set sub-indentation level
int
subLevel
=
__indentLevel
+
1
;
// Count step
lockStep
++;
// Print each element in the trace, the start of the trace is
// always the top-most entry
String
lastClass
=
"<Unknown>"
;
...
...
@@ -160,8 +167,14 @@ public final class CallTraceUtils
__out
.
append
(
current
.
toAtLineString
());
LineEndingUtils
.
append
(
__out
);
// Count step
lockStep
++;
}
// Count step
lockStep
++;
// Print the exception cause, if any
if
(
__cause
!=
null
)
{
...
...
@@ -175,6 +188,9 @@ public final class CallTraceUtils
subLevel
+
1
);
}
// Count step
lockStep
++;
// Then print any suppressed exceptions
if
(
__suppressed
!=
null
)
for
(
Throwable
__throwable
:
__suppressed
)
...
...
@@ -205,6 +221,15 @@ public final class CallTraceUtils
// Give up
catch
(
Throwable
ignored
)
{
try
{
__out
.
append
(
'%'
);
__out
.
append
((
char
)(
'0'
+
lockStep
));
__out
.
append
(
'%'
);
}
catch
(
Throwable
ignored2
)
{
}
}
// Just report that this happened
...
...
modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/lang/ApiLevel.java
View file @
795433b4
...
...
@@ -10,9 +10,6 @@
package
cc.squirreljme.runtime.cldc.lang
;
import
cc.squirreljme.jvm.Assembly
;
import
cc.squirreljme.jvm.SystemCallIndex
;
/**
* Provides access to the current API level.
*
...
...
@@ -27,11 +24,6 @@ import cc.squirreljme.jvm.SystemCallIndex;
@Deprecated
public
final
class
ApiLevel
{
/** The current API level. */
@Deprecated
public
static
final
int
CURRENT_LEVEL
=
Assembly
.
sysCallV
(
SystemCallIndex
.
API_LEVEL
);
/** Undefined. */
@Deprecated
public
static
final
int
UNDEFINED
=
...
...
@@ -79,18 +71,5 @@ public final class ApiLevel
__l
%
1000
,
2000
+
((
__l
/
1000
)
%
100
));
}
/**
* Checks if the runtime API level is at a minimum this given level.
*
* @param __l The level to check.
* @return If the minimum level is met.
* @since 2019/02/02
*/
@Deprecated
public
static
boolean
minimumLevel
(
int
__l
)
{
return
(
ApiLevel
.
CURRENT_LEVEL
>=
__l
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment