Skip to content

Commit 2c9c835

Browse files
committed
implemented a dbg_SetLocalVariable (scriba_SetVariable is global only)
1 parent 7c056c6 commit 2c9c835

File tree

10 files changed

+193
-40
lines changed

10 files changed

+193
-40
lines changed

CVariable.cls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Public isGlobal As Boolean
1515
Private m_name As String
1616
Private m_value As Variant
1717
Public varType As String
18-
Public index As Long 'for arrays
18+
Public Index As Long 'for arrays this is array index, for local variables this is its offset it local var table..
1919
Public pAryElement As Long
2020

2121
Property Let name(v As String)
@@ -26,7 +26,7 @@ Property Get name() As String
2626
name = m_name
2727
End Property
2828

29-
Property Let value(v As String)
29+
Property Let Value(v As String)
3030
If Left(v, 5) = "ARRAY" And InStr(v, "@ 0x") > 0 Then
3131
tmp = Split(v, "@ 0x")
3232
m_value = tmp(0)
@@ -36,6 +36,6 @@ Property Let value(v As String)
3636
End If
3737
End Property
3838

39-
Property Get value() As String
40-
value = m_value
39+
Property Get Value() As String
40+
Value = m_value
4141
End Property

Form1.frm

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ Private Sub RefreshVariables()
474474
li.SubItems(1) = v.name
475475
li.SubItems(2) = v.varType
476476
li.SubItems(3) = v.Value
477-
If v.varType = "array" Then li.Tag = v.pAryElement
477+
Set li.Tag = v
478478
Next
479479

480480
End Sub
@@ -582,22 +582,28 @@ Private Sub mnuVarSetValue_Click()
582582
If Not running Then Exit Sub
583583
If selVariable Is Nothing Then Exit Sub
584584

585-
Dim name As String, Value As String, newVal As String
585+
Dim Value As String, newVal As String
586+
Dim v As CVariable
586587

587588
If selVariable.SubItems(2) = "array" Then
588589
lvVars_DblClick
589-
Exit Sub 'unless they want to change the var type here? todo
590+
Exit Sub 'unless they want to change the var type here? todo?
590591
End If
591592

592-
name = selVariable.SubItems(1)
593-
Value = selVariable.SubItems(3)
593+
On Error Resume Next
594+
Set v = selVariable.Tag
595+
If v Is Nothing Then
596+
MsgBox "Variable tag not set?"
597+
Exit Sub
598+
End If
594599

600+
Value = selVariable.SubItems(3)
595601
If Left(Value, 1) = """" Then Value = Mid(Value, 2)
596602
If Right(Value, 1) = """" Then Value = Mid(Value, 1, Len(Value) - 1)
597603

598604
newVal = InputBox("Modify variable " & name, , Value)
599605
If Len(newVal) > 0 And newVal <> Value Then
600-
SetVariable name, newVal
606+
SetVariable v, newVal
601607
RefreshVariables
602608
End If
603609

@@ -1003,7 +1009,7 @@ Private Sub Form_Unload(Cancel As Integer)
10031009
Call SaveMySetting("includeDir", includeDir)
10041010
Call SaveMySetting("moduleDir", moduleDir)
10051011
FormPos Me, True, True
1006-
'FreeLibrary hsbLib
1012+
FreeLibrary hsbLib
10071013
End Sub
10081014

10091015
Public Sub SyncUI()
@@ -1037,7 +1043,7 @@ End Sub
10371043

10381044
Private Sub ts_Click()
10391045
Dim i As Long
1040-
i = ts.SelectedItem.Index
1046+
i = ts.SelectedItem.index
10411047
txtOut.Visible = IIf(i = 1, True, False)
10421048
lvErrors.Visible = IIf(i = 2, True, False)
10431049
lvVars.Visible = IIf(i = 3, True, False)

Module1.bas

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ Private Declare Sub SetDefaultDirs Lib "sb_engine" (ByRef incDir As Byte, ByRef
3131
Private Declare Sub dbg_WriteFlatSourceFile Lib "sb_engine" (ByVal hDebug As Long, ByRef fpath As Byte)
3232
Private Declare Function dbg_SourceLineCount Lib "sb_engine" (ByVal hDebug As Long) As Long
3333
'
34-
'int __stdcall SetVariable(pSbProgram pProgram, int isLong, BSTR* bvarName, BSTR* bbuf){
35-
Private Declare Function sbSetVariable Lib "sb_engine" (ByVal hProgram As Long, ByVal isLong As Long, ByVal bstrVarName As Long, ByVal bstrValue As Long) As Long
34+
'int __stdcall sbSetGlobalVariable(pSbProgram pProgram, int isLong, BSTR* bvarName, BSTR* bbuf){
35+
Private Declare Function sbSetGlobalVariable Lib "sb_engine" (ByVal hProgram As Long, ByVal isLong As Long, ByVal bstrVarName As Long, ByVal bstrValue As Long) As Long
36+
37+
'int __stdcall dbg_SetLocalVariable(pDebuggerObject pDO, long index, int isLong, BSTR *bbuf)
38+
Private Declare Function dbg_SetLocalVariable Lib "sb_engine" (ByVal hDebug As Long, ByVal index As Long, ByVal isLong As Long, ByVal bstrValue As Long) As Long
39+
3640

3741
Public hProgram As Long
3842
Public hDebugObject As Long 'handle to the current debug object - pDO
@@ -78,26 +82,32 @@ Enum Debug_Commands
7882
dc_Manual = 8
7983
End Enum
8084

81-
Function SetVariable(ByVal name As String, ByVal Value As String) As Boolean
85+
Function SetVariable(v As CVariable, ByVal Value As String) As Boolean
8286

8387
On Error Resume Next
84-
Dim v As Long
88+
Dim x As Long
8589
Dim isNumeric As Long
90+
Dim name As String
8691

92+
name = v.name
8793
If InStr(name, "::") < 1 Then name = "main::" & name
8894

8995
If Left(Value, 2) = "0x" Then
90-
v = CLng("&h" & Mid(Value, 3))
96+
x = CLng("&h" & Mid(Value, 3))
9197
If Err.Number = 0 Then
92-
Value = v
98+
Value = x
9399
isNumeric = 1
94100
End If
95101
Else
96-
v = CLng(Value)
102+
x = CLng(Value)
97103
If Err.Number = 0 Then isNumeric = 1
98104
End If
99105

100-
SetVariable = sbSetVariable(hProgram, isNumeric, VarPtr(name), VarPtr(Value))
106+
If v.isGlobal Then
107+
SetVariable = sbSetGlobalVariable(hProgram, isNumeric, VarPtr(name), VarPtr(Value))
108+
Else
109+
SetVariable = dbg_SetLocalVariable(hDebugObject, v.index, isNumeric, VarPtr(Value))
110+
End If
101111

102112
End Function
103113

@@ -321,7 +331,9 @@ Public Sub HandleDebugMessage(msg As String)
321331
If Left(msg, 10) = "Call-Stack" Then
322332
cmd = Split(msg, ":", 3)
323333
ElseIf Left(msg, 14) = "Array-Variable" Then
324-
cmd = Split(msg, ":", 4)
334+
cmd = Split(msg, ":", 5)
335+
ElseIf Left(msg, 19) = "Local-Variable-Name" Then
336+
cmd = Split(msg, ":", 3)
325337
Else
326338
cmd = Split(msg, ":", 2)
327339
End If
@@ -337,7 +349,8 @@ Public Sub HandleDebugMessage(msg As String)
337349

338350
Case "Local-Variable-Name"
339351
Set v = New CVariable
340-
v.name = cmd(1)
352+
v.index = CLng(cmd(1))
353+
v.name = cmd(2)
341354
v.Value = GetVariableValue(v.name)
342355
v.varType = VariableType(v.name)
343356
variables.Add v
@@ -354,17 +367,18 @@ Public Sub HandleDebugMessage(msg As String)
354367

355368
Case "Call-Stack"
356369
Set c = New cCallStack
357-
c.Index = callStack.count
370+
c.index = callStack.count
358371
c.lineNo = CLng(cmd(1))
359372
c.func = cmd(2)
360373
callStack.Add c
361374
handled = True
362375

363-
Case "Array-Variable" 'Array-Variable:%d:%d:%s , index, varType, buf);
376+
Case "Array-Variable" '"Array-Variable:%d:%d:%d:%s", i, TYPE(v2), v2, buf);
364377
Set v = New CVariable
365-
v.Index = CLng(cmd(1))
378+
v.index = CLng(cmd(1))
366379
v.varType = VariableTypeToString(CLng(cmd(2)))
367-
v.Value = cmd(3) 'if is array then aryPointer will be parsed from value..
380+
v.pAryElement = cmd(3)
381+
v.Value = cmd(4) 'if is array then aryPointer will be parsed from value..
368382
variables.Add v
369383
handled = True
370384

engine/dllmain.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int __stdcall GetErrorString(unsigned int iErrorCode, char* buf, int bufSz){
5454

5555
}
5656

57-
int __stdcall sbSetVariable(pSbProgram pProgram, int isLong, BSTR* bvarName, BSTR* bbuf){
57+
int __stdcall sbSetGlobalVariable(pSbProgram pProgram, int isLong, BSTR* bvarName, BSTR* bbuf){
5858
#pragma EXPORT
5959

6060
int serial, rv;
@@ -78,6 +78,32 @@ int __stdcall sbSetVariable(pSbProgram pProgram, int isLong, BSTR* bvarName, BST
7878

7979
}
8080

81+
/*
82+
int __stdcall sbSetVariableByPointer(pSbProgram pProgram, int isLong, VARIABLE v, BSTR* bbuf){
83+
#pragma EXPORT
84+
85+
int serial, rv;
86+
87+
if(bvarName==0 || bbuf==0) return 0;
88+
89+
std::string varName = __B2S(*bvarName);
90+
std::string buf = __B2S(*bbuf);
91+
92+
serial = scriba_LookupVariableByName(pProgram, (char*)varName.c_str() );
93+
if(serial==0) return 0;
94+
95+
if(isLong==1){
96+
long lVal = atol( buf.c_str() );
97+
rv = scriba_SetVariable(pProgram,serial, SBT_LONG, lVal, 0, 0, 0);
98+
}else{
99+
rv = scriba_SetVariable(pProgram,serial, SBT_STRING, 0, 0, (char*)buf.c_str(), buf.length() );
100+
}
101+
102+
return rv;
103+
104+
}
105+
*/
106+
81107
int __stdcall run_script(char* fPath, int use_debugger)
82108
{
83109
#pragma EXPORT

engine/preprocessors/vb_dbg/debugger.c

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ enum Debug_Commands{
4646
dc_Manual = 8
4747
};
4848

49+
char* __B2C(BSTR bString)
50+
{
51+
int i;
52+
int n = (int)SysStringLen(bString);
53+
char *sz;
54+
sz = (char *)malloc(n + 1);
55+
56+
for(i = 0; i < n; i++){
57+
sz[i] = (char)bString[i];
58+
}
59+
sz[i] = 0;
60+
return sz;
61+
}
62+
4963
int LineNumberForNode(pDebuggerObject pDO, int node)
5064
{
5165
if( node < 1 || node > pDO->cNodes ) return 0;
@@ -1042,6 +1056,66 @@ int MyExecBefore(pExecuteObject pEo)
10421056
*/
10431057

10441058

1059+
1060+
int __stdcall dbg_SetLocalVariable(pDebuggerObject pDO, long index, int isLong, BSTR *bbuf)
1061+
{
1062+
#pragma EXPORT
1063+
1064+
pUserFunction_t pUF;
1065+
pDebugCallStack_t StackListPointer;
1066+
pFixSizeMemoryObject locals;
1067+
VARIABLE v = NULL;
1068+
int lVal;
1069+
char* buf;
1070+
int rv = 0;
1071+
int size = 0;
1072+
1073+
if(bbuf==0) return 0;
1074+
buf = __B2C(*bbuf);
1075+
size = strlen(buf);
1076+
1077+
StackListPointer = pDO->StackListPointer;
1078+
if( pDO->pEo->ProgramCounter == StackListPointer->pUF->NodeId )
1079+
{
1080+
/* In this case the debug call stack was already created to handle the function,
1081+
but the LocalVariables still hold the value of the caller local variables.*/
1082+
if( pDO->StackListPointer->up == NULL || pDO->StackListPointer->up->pUF == NULL ) goto cleanup;
1083+
StackListPointer = StackListPointer->up;
1084+
}
1085+
1086+
pUF = StackListPointer->pUF;
1087+
//if( !StackListPointer->LocalVariables ) goto cleanup;
1088+
1089+
locals = StackListPointer->LocalVariables;
1090+
//index = index - locals->ArrayLowLimit;
1091+
if( index < 0 || index > pUF->cLocalVariables) goto cleanup;
1092+
1093+
v = locals->Value.aValue[index];
1094+
if( v != NULL )
1095+
{
1096+
memory_ReleaseVariable(pDO->pEo->pMo, v);
1097+
locals->Value.aValue[index] = NULL;
1098+
}
1099+
1100+
if(isLong){
1101+
lVal = atol(buf);
1102+
locals->Value.aValue[index] = memory_NewLong(pDO->pEo->pMo);
1103+
if( locals->Value.aValue[index] == NULL ){ rv= SCRIBA_ERROR_MEMORY_LOW; goto cleanup;}
1104+
locals->Value.aValue[index]->Value.lValue = lVal;
1105+
}else{
1106+
locals->Value.aValue[index] = memory_NewString(pDO->pEo->pMo, size);
1107+
if( locals->Value.aValue[index] == NULL ){ rv= SCRIBA_ERROR_MEMORY_LOW; goto cleanup;}
1108+
memcpy(locals->Value.aValue[index]->Value.pValue, buf, size);
1109+
}
1110+
1111+
return SCRIBA_ERROR_SUCCESS;
1112+
1113+
cleanup:
1114+
free(buf);
1115+
return 0;
1116+
}
1117+
1118+
10451119
/*
10461120
return values:
10471121
0 = Success
@@ -1074,7 +1148,7 @@ void __stdcall dbg_EnumAryVarsByPointer(pDebuggerObject pDO, VARIABLE v)
10741148
if(v2 != NULL){
10751149
sz = 1024;
10761150
SPrintVariable(pDO, v2, buf, &sz);
1077-
snprintf(cBuffer,1110, "Array-Variable:%d:%d:%s", i, TYPE(v2), buf);
1151+
snprintf(cBuffer,1110, "Array-Variable:%d:%d:%d:%s", i, TYPE(v2), v2, buf);
10781152
vbStdOut(cb_debugger, cBuffer, strlen(cBuffer));
10791153
}
10801154
}
@@ -1124,7 +1198,7 @@ void __stdcall dbg_EnumVars(pDebuggerObject pDO)
11241198
if( StackListPointer->LocalVariables ){
11251199
for(i=StackListPointer->LocalVariables->ArrayLowLimit ; i <= StackListPointer->LocalVariables->ArrayHighLimit ; i++ )
11261200
{
1127-
snprintf(cBuffer,1024,"Local-Variable-Name:%s",pUF->ppszLocalVariables[i-1]);
1201+
snprintf(cBuffer,1024,"Local-Variable-Name:%d:%s", i-1, pUF->ppszLocalVariables[i-1]);
11281202
vbStdOut(cb_debugger, cBuffer, strlen(cBuffer));
11291203
}
11301204
}

engine/sb_engine.dll

1 KB
Binary file not shown.

0 commit comments

Comments
 (0)