// File: /workspace/github_c_makefile_star2_O1/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 0x4e6d
movw $0x0, 0x38(%rbx)
jmp 0x4f16
movq 0x18(%rbx), %rax
movq 0xb8(%rax), %rcx
movq %rcx, 0x40(%rbx)
movq 0xc0(%rax), %rax
movq %rax, (%rcx)
movq 0x18(%rbx), %rdi
leaq 0x9673(%rip), %rsi      # 0xe504
callq 0x3a0f
testq %rax, %rax
je 0x4ea6
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6eaf
movq 0x18(%rbx), %rax
movq 0xc0(%rax), %r14
movq %r14, %rdi
callq 0xbab6
orl $0x2, %eax
leaq 0x118(%rbx), %rdi
cmpl $0x16, %eax
jne 0x4ee6
leaq 0x13021(%rip), %rax     # 0x17ef0
movq (%rax,%r14,8), %rdx
leaq 0x9632(%rip), %rsi      # 0xe50c
movq %r14, %rcx
xorl %eax, %eax
callq 0x32f0
jmp 0x4ef8
movq 0x10(%r14), %rdx
leaq 0x9637(%rip), %rsi      # 0xe528
xorl %eax, %eax
callq 0x32f0
leaq 0x118(%rbx), %rsi
movq %rbx, %rdi
callq 0x6c86
leaq 0x96e3(%rip), %rsi      # 0xe5f1
movq %rbx, %rdi
callq 0x6c86
movq %rbx, %rdi
callq 0x6a72
movzbl (%rdx), %ecx
leal -0x67(%rcx), %eax
cmpl $0xa, %eax
ja 0x4f6f
leaq 0x93a8(%rip), %rcx      # 0xe2d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x699a
movq 0x40(%rbx), %rsi
movq %rax, %rdi
callq 0xc80e
testq %rax, %rax
je 0x5057
movq 0x60(%rbx), %rdi
movq %rax, %rsi
callq 0x436a
movq %rbx, %rdi
callq 0x50a4
jmp 0x5066
cmpl $0x78, %ecx
jne 0x4fc1
movq 0x48(%rbx), %r14
movq 0x88(%rbx), %rsi
movq 0x90(%rbx), %rdx
addq 0x80(%rbx), %rdx
subq %rdx, %rsi
movq %rbx, %rdi
callq 0x6d08
cmpl $0xfffffeff, %eax       # imm = 0xFFFFFEFF
jne 0x4fb7
movq %r14, 0x48(%rbx)
leaq 0x93bf(%rip), %rsi      # 0xe369
movq %rbx, %rdi
callq 0x6c86
movl $0xfffffefe, %eax       # imm = 0xFFFFFEFE
movq %rbx, %rdi
movl %eax, %esi
jmp 0x506e
leaq 0x9581(%rip), %rsi      # 0xe549
movq %rbx, %rdi
callq 0x6c86
leaq 0x961a(%rip), %rsi      # 0xe5f1
jmp 0x505e
leaq 0x905e(%rip), %rsi      # 0xe041
movq %rbx, %rdi
callq 0x6c86
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
jmp 0x506e
movq 0x18(%rbx), %rdi
leaq 0x9434(%rip), %rsi      # 0xe434
callq 0x3a0f
movq %rax, %r14
movq 0x40(%rbx), %rax
movq (%rax), %rdi
callq 0xbab6
cmpl $0x7, %eax
je 0x501e
cmpl $0x2, %eax
jne 0x5048
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 0x5233
leaq 0x94d4(%rip), %rsi      # 0xe532
movq %rbx, %rdi
callq 0x6c86
movq %rbx, %rdi
movl $0xfffffefe, %esi       # imm = 0xFFFFFEFE
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x6869