// File: /workspace/github_c_makefile_star2_O2/hoobaa[P]ficl/tools.c
// Function: ficlPrimitiveStepBreak
static void ficlPrimitiveStepBreak(ficlVm *vm)
{
    ficlString command;
    ficlWord *word;
    ficlWord *pOnStep;
    ficlWordKind kind;

    if (!vm->restart)
    {
        FICL_VM_ASSERT(vm, vm->callback.system->breakpoint.address);
        FICL_VM_ASSERT(vm, vm->callback.system->breakpoint.oldXT);
        /*
        ** Clear the breakpoint that caused me to run
        ** Restore the original instruction at the breakpoint, 
        ** and restore the IP
        */
        vm->ip = (ficlIp)(vm->callback.system->breakpoint.address);
        *vm->ip = vm->callback.system->breakpoint.oldXT;

        /*
        ** If there's an onStep, do it
        */
        pOnStep = ficlSystemLookup(vm->callback.system, "on-step");
        if (pOnStep)
            ficlVmExecuteXT(vm, pOnStep);

        /*
        ** Print the name of the next instruction
        */
        word = vm->callback.system->breakpoint.oldXT;

        kind = ficlWordClassify(word);

        switch (kind)
        {
			case FICL_WORDKIND_INSTRUCTION:
			case FICL_WORDKIND_INSTRUCTION_WITH_ARGUMENT:
				sprintf(vm->pad, "next: %s (instruction %ld)\n", ficlDictionaryInstructionNames[(long)word], (long)word);
				break;
			default:
				sprintf(vm->pad, "next: %s\n", word->name);
				break;
		}

        ficlVmTextOut(vm, vm->pad);
        ficlDebugPrompt(vm);
    }
    else
    {
        vm->restart = 0;
    }

    command = ficlVmGetWord(vm);

	switch (command.text[0])
	{
		case 'i':
		    ficlPrimitiveStepIn(vm);
			break;

		case 'o':
		    ficlPrimitiveStepOver(vm);
			break;

		case 'g':
			break;

		case 'l':
		{
			ficlWord *xt;
			xt = ficlDictionaryFindEnclosingWord(ficlVmGetDictionary(vm), (ficlCell *)(vm->ip));
			if (xt)
			{
				ficlStackPushPointer(vm->dataStack, xt);
				ficlPrimitiveSeeXT(vm);
			}
			else
			{
				ficlVmTextOut(vm, "sorry - can't do that\n");
			}
			ficlVmThrow(vm, FICL_VM_STATUS_RESTART);
			break;
		}

		case 'q':
		{
			ficlVmTextOut(vm, FICL_PROMPT);
			ficlVmThrow(vm, FICL_VM_STATUS_ABORT);
			break;
		}

		case 'x':
		{
			/*
			** Take whatever's left in the TIB and feed it to a subordinate ficlVmExecuteString
			*/ 
			int returnValue;
			ficlString s;
			ficlWord *oldRunningWord = vm->runningWord;

			FICL_STRING_SET_POINTER(s, vm->tib.text + vm->tib.index);
			FICL_STRING_SET_LENGTH(s, vm->tib.end - FICL_STRING_GET_POINTER(s));

			returnValue = ficlVmExecuteString(vm, s);

			if (returnValue == FICL_VM_STATUS_OUT_OF_TEXT)
			{
				returnValue = FICL_VM_STATUS_RESTART;
				vm->runningWord = oldRunningWord;
				ficlVmTextOut(vm, "\n");
			}

			ficlVmThrow(vm, returnValue);
			break;
		}

		default:
		{
			ficlVmTextOut(vm,
				"i -- step In\n"
				"o -- step Over\n"
				"g -- Go (execute to completion)\n"
				"l -- List source code\n"
				"q -- Quit (stop debugging and abort)\n"
				"x -- eXecute the rest of the line as Ficl words\n"
			);
			ficlDebugPrompt(vm);
			ficlVmThrow(vm, FICL_VM_STATUS_RESTART);
			break;
		}
	}

    return;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpw $0x0, 0x38(%rdi)
je 0x4d0b
andw $0x0, 0x38(%rbx)
jmp 0x4dad
movq 0x18(%rbx), %rax
movq 0xb8(%rax), %rcx
movq %rcx, 0x40(%rbx)
movq 0xc0(%rax), %rax
movq %rax, (%rcx)
movq 0x18(%rbx), %rdi
leaq 0x97d5(%rip), %rsi      # 0xe504
callq 0x3977
testq %rax, %rax
je 0x4d44
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6ad4
movq 0x18(%rbx), %rax
movq 0xc0(%rax), %r14
movq %r14, %rdi
callq 0xb28e
orl $0x2, %eax
leaq 0x118(%rbx), %rdi
cmpl $0x16, %eax
jne 0x4d84
leaq 0x14183(%rip), %rax     # 0x18ef0
movq (%rax,%r14,8), %rdx
leaq 0x9794(%rip), %rsi      # 0xe50c
movq %r14, %rcx
xorl %eax, %eax
callq 0x32f0
jmp 0x4d96
movq 0x10(%r14), %rdx
leaq 0x9799(%rip), %rsi      # 0xe528
xorl %eax, %eax
callq 0x32f0
leaq 0x118(%rbx), %rsi
movq %rbx, %rdi
callq 0x68f1
movq %rbx, %rdi
callq 0x50fe
movq %rbx, %rdi
callq 0x6713
movzbl (%rdx), %ecx
leal -0x67(%rcx), %eax
cmpl $0xa, %eax
ja 0x4e06
leaq 0x9511(%rip), %rcx      # 0xe2d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x6643
movq 0x40(%rbx), %rsi
movq %rax, %rdi
callq 0xbe27
testq %rax, %rax
je 0x4eed
movq 0x60(%rbx), %rdi
movq %rax, %rsi
callq 0x4287
movq %rbx, %rdi
callq 0x4f3a
jmp 0x4efc
cmpl $0x78, %ecx
jne 0x4e58
movq 0x48(%rbx), %r14
movq 0x88(%rbx), %rsi
movq 0x90(%rbx), %rdx
addq 0x80(%rbx), %rdx
subq %rdx, %rsi
movq %rbx, %rdi
callq 0x6970
cmpl $0xfffffeff, %eax       # imm = 0xFFFFFEFF
jne 0x4e4e
movq %r14, 0x48(%rbx)
leaq 0x9528(%rip), %rsi      # 0xe369
movq %rbx, %rdi
callq 0x68f1
movl $0xfffffefe, %eax       # imm = 0xFFFFFEFE
movq %rbx, %rdi
movl %eax, %esi
jmp 0x4f04
leaq 0x96ea(%rip), %rsi      # 0xe549
movq %rbx, %rdi
callq 0x68f1
movq %rbx, %rdi
callq 0x50fe
jmp 0x4efc
leaq 0x91c6(%rip), %rsi      # 0xe041
movq %rbx, %rdi
callq 0x68f1
pushq $-0x1
popq %rsi
movq %rbx, %rdi
jmp 0x4f04
movq 0x18(%rbx), %rdi
leaq 0x959e(%rip), %rsi      # 0xe434
callq 0x3977
movq %rax, %r14
movq 0x40(%rbx), %rax
movq (%rax), %rdi
callq 0xb28e
cmpl $0x7, %eax
je 0x4eb4
cmpl $0x2, %eax
jne 0x4ede
movq 0x18(%rbx), %rax
movq 0x40(%rbx), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0xb8(%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0xc0(%rax)
movq %r14, 0x8(%rcx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x510a
leaq 0x963e(%rip), %rsi      # 0xe532
movq %rbx, %rdi
callq 0x68f1
movq %rbx, %rdi
movl $0xfffffefe, %esi       # imm = 0xFFFFFEFE
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x6517