filter exception handlers by catch_type
This commit is contained in:
parent
e163621ebe
commit
832c182471
2
Makefile
2
Makefile
@ -7,7 +7,7 @@ CC ?= gcc
|
||||
ARCH = -m32
|
||||
CFLAGS += -Wall -Werror -Wfatal-errors -Wno-error=unused-variable -fstack-protector -std=c2x -g
|
||||
CFLAGS += -DDEBUG
|
||||
CFLAGS += -DDEBUG_PRINT
|
||||
#CFLAGS += -DDEBUG_PRINT
|
||||
LDFLAGS = -lm
|
||||
OPT ?= -O0
|
||||
DEPFLAGS = -MMD -MP
|
||||
|
@ -464,6 +464,8 @@ struct method_entry class_resolver_lookup_method_from_interfacemethodref_index(i
|
||||
assert(class_entry != nullptr);
|
||||
}
|
||||
|
||||
print__class_file__class_name(objectref_class_entry->class_file);
|
||||
printc('\n');
|
||||
assert(!"interfacemethodref method does not exist");
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,13 @@ void debug_print__method_info__method_name(struct class_file * class_file, struc
|
||||
debug_print__constant__method_name(method_name_constant, method_descriptor_constant);
|
||||
}
|
||||
|
||||
void print__string(const uint8_t * bytes, int length)
|
||||
{
|
||||
for (int i = 0; i < length; i++) {
|
||||
printc(bytes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void print__constant__utf8_string(struct constant * constant)
|
||||
{
|
||||
assert(constant->tag == CONSTANT_Utf8);
|
||||
|
@ -9,6 +9,7 @@ void debug_print__class_file__class_name(struct class_file * class_file);
|
||||
void debug_print__constant__method_name(struct constant * name_constant, struct constant * descriptor_constant);
|
||||
void debug_print__method_info__method_name(struct class_file * class_file, struct method_info * method_info);
|
||||
|
||||
void print__string(const uint8_t * bytes, int length);
|
||||
void print__constant__utf8_string(struct constant * constant);
|
||||
void print__class_file__class_name(struct class_file * class_file);
|
||||
void print__constant__method_name(struct constant * name_constant, struct constant * descriptor_constant);
|
||||
|
30
c/frame.c
30
c/frame.c
@ -497,7 +497,14 @@ void vm_exception(struct vm * vm, int32_t * objectref)
|
||||
while (vm->frame_stack.ix > 0) {
|
||||
for (int i = 0; i < vm->current_frame->code_attribute->exception_table_length; i++) {
|
||||
struct exception_table_entry * entry = &vm->current_frame->code_attribute->exception_table[i];
|
||||
if (vm->current_frame->pc >= entry->start_pc && vm->current_frame->pc < entry->end_pc) {
|
||||
bool caught =
|
||||
vm->current_frame->pc >= entry->start_pc &&
|
||||
vm->current_frame->pc < entry->end_pc &&
|
||||
exception_class_entry == class_resolver_lookup_class_from_class_index(vm->class_hash_table.length,
|
||||
vm->class_hash_table.entry,
|
||||
vm->current_frame->class_entry,
|
||||
entry->catch_type);
|
||||
if (caught) {
|
||||
operand_stack_push_u32(vm->current_frame, (uint32_t)objectref);
|
||||
vm->current_frame->next_pc = entry->handler_pc;
|
||||
|
||||
@ -515,10 +522,27 @@ void vm_exception(struct vm * vm, int32_t * objectref)
|
||||
vm->current_frame = stack_pop_frame(&vm->frame_stack, 1);
|
||||
}
|
||||
|
||||
prints("exception: ");
|
||||
print__class_file__class_name(exception_class_entry->class_file);
|
||||
printc('\n');
|
||||
{
|
||||
int32_t * string_objectref = (int32_t *)objectref[2];
|
||||
if (string_objectref != nullptr) {
|
||||
prints(" message: ");
|
||||
struct class_entry * string_class_entry = (struct class_entry *)string_objectref[0];
|
||||
prints("(class: ");
|
||||
print__class_file__class_name(string_class_entry->class_file);
|
||||
printc(')');
|
||||
prints("\n ");
|
||||
int32_t * arrayref = (int32_t *)string_objectref[1];
|
||||
int32_t length = arrayref[0];
|
||||
uint8_t * bytes = (uint8_t *)&arrayref[1];
|
||||
print__string(bytes, length);
|
||||
printc('\n');
|
||||
}
|
||||
}
|
||||
assert(objectref[1] != 0);
|
||||
backtrace_print((struct backtrace *)objectref[1]);
|
||||
|
||||
assert(!"exception");
|
||||
}
|
||||
|
||||
static void print_vm_stack(struct vm * vm)
|
||||
|
@ -48,6 +48,10 @@ public class PrintStream
|
||||
write(String.valueOf(obj));
|
||||
}
|
||||
|
||||
public void print(String s) {
|
||||
write(String.valueOf(s));
|
||||
}
|
||||
|
||||
public void println() {
|
||||
write(newline);
|
||||
}
|
||||
@ -91,4 +95,9 @@ public class PrintStream
|
||||
write(String.valueOf(obj));
|
||||
write(newline);
|
||||
}
|
||||
|
||||
public void println(String s) {
|
||||
write(String.valueOf(s));
|
||||
write(newline);
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,27 @@
|
||||
package p;
|
||||
|
||||
class Exception2 extends Exception {
|
||||
public Exception2(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
class TestException {
|
||||
static void test2() throws Exception {
|
||||
throw new Exception("asdf exception");
|
||||
static void test2() throws Exception2 {
|
||||
throw new Exception2("asdf exception");
|
||||
}
|
||||
|
||||
static void test() throws Exception {
|
||||
// try {
|
||||
static void test() throws Exception2 {
|
||||
try {
|
||||
test2();
|
||||
//} catch (Exception e) {
|
||||
//System.out.println(e);
|
||||
//throw e;
|
||||
//}
|
||||
} catch (Exception e) {
|
||||
System.out.print("exception handler: ");
|
||||
System.out.println(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main() throws Exception {
|
||||
public static void main() throws Exception2 {
|
||||
test();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user