Page 1 of 1

C backend current limitations while debugging

Posted: Thu Mar 23, 2023 12:57 pm
by luis
If I'm not mistaken, this is the current state of affairs.
Posting here for future reference / checks.
Enable debugger and purifier to test it.

Code: Select all

PurifierGranularity(1,1,1,1)

; Array out of bounds 
; ASM OK
; C not working / still not implemented (see https://www.purebasic.fr/english/viewtopic.php?t=81031 )
Dim a(10)
For k = 0 To 11
 a(k) = 123 
Next

; Global variable overflow 
; ASM OK
; C not supported (see https://www.purebasic.fr/english/viewtopic.php?p=573179 )
Global var.b
PokeI(@var, 123456) 

; Local variable overflow  
; ASM OK
; C not supported (see https://www.purebasic.fr/english/viewtopic.php?p=573179 )
Procedure foo()
 Protected var.b
 PokeI(@var, 123456) 
EndProcedure : foo()

; Allocated memory area overflow 
; ASM OK
; C OK
*p = AllocateMemory(16)
For k = 0 To 16
 PokeB(*p + k, $80) 
Next

; String memory block overflow
; ASM OK
; C OK
a$ = "12345678"
PokeB(@a$ + SizeOf(Character) * 9, $80)

EDIT: "Array out of bounds" fixed
viewtopic.php?t=81031

Re: C backend current limitations while debugging

Posted: Sat Mar 25, 2023 6:51 am
by juergenkulow

Code: Select all

//purebasic.c  compared With purebasic.asm 
// a(k) = 123 
DBG_Check(7);
((integer*)a_a.a)[(integer)v_k]=123;

; a(k) = 123 
  MOV    rdi,7
  CALL   DBL
  MOV    r15,qword [v_k]
  MOV    rax,r15
  MOV    rdx,qword [a_a]
  MOV    rdx,[rdx-16]
  CALL  _DBG_A
  MOV    rbp,qword [a_a]
  SAL    r15,3
  MOV    qword [rbp+r15],123
  
  
// PokeI(@var, 123456) 
DBG_Check(14);
quad p0=(quad)((integer)(&v_var));
PB_PokeI_DEBUG(p0,123456LL);
integer rr1=PB_PokeI(p0,123456LL);
PB_PURIFIER_Check(0,0,0)         ;

; PokeI(@var, 123456) 
  MOV    rdi,14
  CALL   DBL
  PUSH   qword 123456
  LEA    rax,[v_var]
  MOV    rax,rax
  PUSH   rax
  POP    rdi
  POP    rsi
  MOV    r10,PB_PokeI_DEBUG
  MOV    r11,0
  CALL  _DBG_CallDebug
  CALL   PB_PokeI
  XOr    rdx,rdx
  XOr    rsi,rsi
  MOV    rdi,qword PMG
  CALL   PB_PURIFIER_Check
  
  
// Protected var.b;
// PokeI(@var, 123456) 
DBG_Check(21);
quad p1=(quad)((integer)(&v_var));
PB_PokeI_DEBUG(p1,123456LL);
integer rr2=PB_PokeI(p1,123456LL);
PB_PURIFIER_Check(0,0,0)         ;
  
  ; PokeI(@var, 123456) 
  MOV    rdi,21
  CALL   DBL
  PUSH   qword 123456
  LEA    rax,[rsp+48]
  MOV    rax,rax
  PUSH   rax
  POP    rdi
  POP    rsi
  MOV    r10,PB_PokeI_DEBUG
  MOV    r11,0
  CALL  _DBG_CallDebug
  CALL   PB_PokeI
  MOV    rdx,rsp
  MOV    rsi,qword PM_0
  MOV    rdi,qword PMG
  CALL   PB_PURIFIER_Check