News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

broken syntax highlighting

Started by Nale, August 17, 2011, 01:16:30 AM

Previous topic - Next topic

Nale

I am having trouble with the syntax highlighting. It breaks whenever an "R" occurs in inline asm. After that, everything is plain black. It's strangely specific though. For example, putting in other letters instead of R or putting a space in makes it start working again. Does anyone know why this could be?

For example
    //highlighting is fine here
    asm(""R"");
    //everything after this is black


Story

#1
Bump. Does anyone know the solution to this?

Edit: Wow, I just realized that I accidentally made two accounts on this forum. This is the same person as the OP.

ollydbg

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Folco

I confirm (svn 7417, Ubuntu 64b). It fails if last character of the string is <R>.
Works fine with other characters I tested.
I will try to investigate this evening, going back to work at the moment.
Kernel Extremist - PedroM power ©

Folco

It could be handled line 603 :
const bool literalString = sc.ch == '\"';
if (literalString || sc.ch == '\'') {
size_t lenS = strlen(s);
const bool raw = literalString && sc.chPrev == 'R';

or line 824 :
} else if (sc.ch == '\"') {
if (sc.chPrev == 'R') {
sc.SetState(SCE_C_STRINGRAW|activitySet);
rawStringTerminator = ")";

of src/sdk/wxscintilla/src/scintilla/lexers/LexCPP.cxx .
Kernel Extremist - PedroM power ©

Jenna

The behaviour seems to be correct.

The cpp-lexers checks for c++0x raw-strings.
They start with an "R" followed by an optional delimiter, followed by a "(".
The problem is that you have double doublequotes before the "R", so it is treated as beginning of a raw-string.
Everything that follows is treated as delimiter (maximal 16 characters, but that's not tested by the lexer), unless an opening brace ( "(" ) follows.
Now the lexer searches for a closing brace, followed by the delimiter and a double-quote.

In normal code, it is very unlikely, that this will ever happen.

So the "issue" comes from the (most likely invalid) use of double double-quotes in your code.

The only issue, I see here, is that the lexer does not check the delimiters length for the maximum allowed 16 characters.
But the question would be, what to do, if the delimiter is to long ?

See: http://en.wikipedia.org/wiki/C%2B%2B0x#New_string_literals

MortenMacFly

Quote from: Folco on August 30, 2011, 01:29:18 PM
It could be handled line 603 :
[...]
or line 824 :
Note that before patching something you should first check if SciTE does the same. If so, we won't change. If it handles this correct the next wxScintilla update might work for you.
But I agree with Jens in this case:
Quote from: jens on August 30, 2011, 02:54:52 PM
The behaviour seems to be correct.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Folco

Indeed, the behaviour seems to be correct (and usually, I don't propose a patch without some watchs here and there :))

By the way, Nale, what means asm(""R""); ?
Trying to compile it, I get obviously Junk at end of line, first char is `"'

I would have understood asm(".byte 'R'"); or asm(".byte \"R\"");, but what do yo mean ?
Note that syntax highlight works fine for the cases above. :)
Kernel Extremist - PedroM power ©

Nale

#8
I am working on KVM, which has R defined as a macro. Here's an example of a complete function.
Actually would it be possible to get a seperate C syntax highlighting mode? There are other oddities due to the different keywords (C coders seem to love naming variables new), though this is the only change that breaks an entire file.

#ifdef CONFIG_X86_64
#define R "r"
#define Q "q"
#else
#define R "e"
#define Q "l"
#endif

static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
unsigned long flags = vmcs_readl(GUEST_RFLAGS);

if (enable_ept && is_paging(vcpu)) {
vmcs_writel(GUEST_CR3, vcpu->arch.cr3);
ept_load_pdptrs(vcpu);
}
/* Record the guest's net vcpu time for enforced NMI injections. */
if (unlikely(!cpu_has_virtual_nmis() && vmx->soft_vnmi_blocked))
vmx->entry_time = ktime_get();

/* Handle invalid guest state instead of entering VMX */
if (vmx->emulation_required && emulate_invalid_guest_state) {
handle_invalid_guest_state(vcpu, kvm_run);
return;
}

if (test_bit(VCPU_REGS_RSP, (unsigned long *)&vcpu->arch.regs_dirty))
vmcs_writel(GUEST_RSP, vcpu->arch.regs[VCPU_REGS_RSP]);
if (test_bit(VCPU_REGS_RIP, (unsigned long *)&vcpu->arch.regs_dirty))
vmcs_writel(GUEST_RIP, vcpu->arch.regs[VCPU_REGS_RIP]);

/* When single-stepping over STI and MOV SS, we must clear the
* corresponding interruptibility bits in the guest state. Otherwise
* vmentry fails as it then expects bit 14 (BS) in pending debug
* exceptions being set, but that's not correct for the guest debugging
* case. */
if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
vmx_set_interrupt_shadow(vcpu, 0);

   if (vcpu->azure.status & RSG_SINGLESTEP){
       //printk(KERN_DEBUG "vmx_vcpu_run active ss azval = %x", vcpu->azure.singlestep);
       flags |= X86_EFLAGS_TF | X86_EFLAGS_RF;
       vmx_set_interrupt_shadow(vcpu, 0);
   } else {
       flags &= ~X86_EFLAGS_TF;
   }
   vmcs_writel(GUEST_RFLAGS, flags);

/*
* Loading guest fpu may have cleared host cr0.ts
*/
vmcs_writel(HOST_CR0, read_cr0());

if (vcpu->arch.switch_db_regs)
set_debugreg(vcpu->arch.dr6, 6);

asm(
/* Store host registers */
"push %%"R"dx; push %%"R"bp;"
"push %%"R"cx \n\t"
"cmp %%"R"sp, %c[host_rsp](%0) \n\t"
"je 1f \n\t"
"mov %%"R"sp, %c[host_rsp](%0) \n\t"
__ex(ASM_VMX_VMWRITE_RSP_RDX) "\n\t"
"1: \n\t"
/* Reload cr2 if changed */
"mov %c[cr2](%0), %%"R"ax \n\t"
"mov %%cr2, %%"R"dx \n\t"
"cmp %%"R"ax, %%"R"dx \n\t"
"je 2f \n\t"
"mov %%"R"ax, %%cr2 \n\t"
"2: \n\t"
/* Check if vmlaunch or vmresume is needed */
"cmpl $0, %c[launched](%0) \n\t"
/* Load guest registers.  Don't clobber flags. */
"mov %c[rax](%0), %%"R"ax \n\t"
"mov %c[rbx](%0), %%"R"bx \n\t"
"mov %c[rdx](%0), %%"R"dx \n\t"
"mov %c[rsi](%0), %%"R"si \n\t"
"mov %c[rdi](%0), %%"R"di \n\t"
"mov %c[rbp](%0), %%"R"bp \n\t"
#ifdef CONFIG_X86_64
"mov %c[r8](%0),  %%r8  \n\t"
"mov %c[r9](%0),  %%r9  \n\t"
"mov %c[r10](%0), %%r10 \n\t"
"mov %c[r11](%0), %%r11 \n\t"
"mov %c[r12](%0), %%r12 \n\t"
"mov %c[r13](%0), %%r13 \n\t"
"mov %c[r14](%0), %%r14 \n\t"
"mov %c[r15](%0), %%r15 \n\t"
#endif
"mov %c[rcx](%0), %%"R"cx \n\t" /* kills %0 (ecx) */

/* Enter guest mode */
"jne .Llaunched \n\t"
__ex(ASM_VMX_VMLAUNCH) "\n\t"
"jmp .Lkvm_vmx_return \n\t"
".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
".Lkvm_vmx_return: "
/* Save guest registers, load host registers, keep flags */
"xchg %0,     (%%"R"sp) \n\t"
"mov %%"R"ax, %c[rax](%0) \n\t"
"mov %%"R"bx, %c[rbx](%0) \n\t"
"push"Q" (%%"R"sp); pop"Q" %c[rcx](%0) \n\t"
"mov %%"R"dx, %c[rdx](%0) \n\t"
"mov %%"R"si, %c[rsi](%0) \n\t"
"mov %%"R"di, %c[rdi](%0) \n\t"
"mov %%"R"bp, %c[rbp](%0) \n\t"
#ifdef CONFIG_X86_64
"mov %%r8,  %c[r8](%0) \n\t"
"mov %%r9,  %c[r9](%0) \n\t"
"mov %%r10, %c[r10](%0) \n\t"
"mov %%r11, %c[r11](%0) \n\t"
"mov %%r12, %c[r12](%0) \n\t"
"mov %%r13, %c[r13](%0) \n\t"
"mov %%r14, %c[r14](%0) \n\t"
"mov %%r15, %c[r15](%0) \n\t"
#endif
"mov %%cr2, %%"R"ax   \n\t"
"mov %%"R"ax, %c[cr2](%0) \n\t"

"pop  %%"R"bp; pop  %%"R"bp; pop  %%"R"dx \n\t"
"setbe %c[fail](%0) \n\t"
     : : "c"(vmx), "d"((unsigned long)HOST_RSP),
[launched]"i"(offsetof(struct vcpu_vmx, launched)),
[fail]"i"(offsetof(struct vcpu_vmx, fail)),
[host_rsp]"i"(offsetof(struct vcpu_vmx, host_rsp)),
[rax]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RAX])),
[rbx]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RBX])),
[rcx]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RCX])),
[rdx]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RDX])),
[rsi]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RSI])),
[rdi]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RDI])),
[rbp]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_RBP])),
#ifdef CONFIG_X86_64
[r8]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R8])),
[r9]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R9])),
[r10]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R10])),
[r11]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R11])),
[r12]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R12])),
[r13]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R13])),
[r14]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R14])),
[r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])),
#endif
[cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2))
     : "cc", "memory"
, R"bx", R"di", R"si"
#ifdef CONFIG_X86_64
, "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
#endif
     );

vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
 | (1 << VCPU_EXREG_PDPTR));
vcpu->arch.regs_dirty = 0;

if (vcpu->arch.switch_db_regs)
get_debugreg(vcpu->arch.dr6, 6);

vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
if (vmx->rmode.irq.pending)
fixup_rmode_irq(vmx);

asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
vmx->launched = 1;

vmx_complete_interrupts(vmx);
}

#undef R
#undef Q