1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
|
/***************************************************************************
breakpoint_cmds.c - breakpoint commands for xsldbg
-------------------
begin : Wed Nov 21 2001
copyright : (C) 2001 by Keith Isdale
email : k_isdale@tpg.com.au
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "xsldbg.h"
#include "debugXSL.h"
#include "files.h"
#include "utils.h"
#include <libxml/valid.h> /* needed for xmlSplitQName2 */
#include <libxml/xpathInternals.h> /* needed for xmlNSLookup */
#include <libxml/uri.h> /* needed for xmlURIEscapeStr */
#include "xsldbgthread.h" /* for getThreadStatus() */
#include "xsldbgmsg.h"
#include "options.h"
/* temp buffer needed occationaly */
static xmlChar buff[DEBUG_BUFFER_SIZE];
/* needed by breakpoint validation */
extern int breakPointCounter;
/* we need to have a fake URL and line number for orphaned template breakpoints */
int orphanedTemplateLineNo = 1;
const xmlChar *orphanedTemplateURL= (xmlChar*)"http://xsldbg.sourceforge.net/default.xsl";
/* ---------------------------------------------------
Private function declarations for breakpoint_cmds.c
----------------------------------------------------*/
/**
* validateSource:
* @url : is valid name of a xsl source file
* @lineNo : lineNo >= 0
*
* Returns 1 if a breakpoint could be set at specified file url and line number
* 0 otherwise
*/
int validateSource(xmlChar ** url, long *lineNo);
/**
* validateData:
* @url : is valid name of a xml data file
* @lineNo : lineNo >= 0
*
* Returns 1 if a breakpoint could be set at specified file url and line number
* 0 otherwise
*/
int validateData(xmlChar ** url, long *lineNo);
/* -------------------------------------
End private functions
---------------------------------------*/
/* -----------------------------------------
BreakPoint related commands
------------------------------------------- */
/**
* xslDbgShellFrameBreak:
* @arg: Is valid number of frames to change location by
* @stepup: If != 1 then we step up, otherwise step down
*
* Set a "frame" break point either up or down from here
*
* Returns 1 on success,
* 0 otherwise
*/
int
xslDbgShellFrameBreak(xmlChar * arg, int stepup)
{
int result = 0;
/* how many frames to go up/down */
int noOfFrames;
static const char *errorPrompt = I18N_NOOP("Failed to add breakpoint.");
if (!filesGetStylesheet() || !filesGetMainDoc()) {
xsldbgGenericErrorFunc(i18n("Error: Debugger has no files loaded. Try reloading files.\n"));
xsldbgGenericErrorFunc(TQString("Error: %1.\n").arg(i18n(errorPrompt)));
return result;
}
if (!arg) {
#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
xsltGenericError(xsltGenericErrorContext,
"Error: NULL argument provided\n");
#endif
xsldbgGenericErrorFunc(TQString("Error: %1\n").arg(i18n(errorPrompt)));
return result;
}
if (xmlStrLen(arg) > 0) {
if (!sscanf((char *) arg, "%d", &noOfFrames)) {
xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as a number of frames.\n").arg((char*)arg));
noOfFrames = -1;
}
} else {
noOfFrames = 0;
}
if (noOfFrames >0){
if (stepup) {
result = callStackStepup(callStackGetDepth() - noOfFrames);
} else {
result = callStackStepdown(callStackGetDepth() + noOfFrames);
}
}
if (!result)
xsldbgGenericErrorFunc(TQString("Error: %1\n").arg(i18n(errorPrompt)));
return result;
}
/**
* validateSource:
* @url : is valid name of a xsl source file
* @lineNo : lineNo >= 0
*
* Returns 1 if a breakpoint could be set at specified file url and line number
* 0 otherwise
*/
int
validateSource(xmlChar ** url, long *lineNo)
{
int result = 0, type;
searchInfoPtr searchInf;
nodeSearchDataPtr searchData = NULL;
if (!filesGetStylesheet()) {
xsldbgGenericErrorFunc(i18n("Error: Stylesheet is not valid or file is not loaded.\n"));
return result;
}
if (!url) {
#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
xsltGenericError(xsltGenericErrorContext,
"Error: NULL argument provided\n");
#endif
return result;
}
searchInf = searchNewInfo(SEARCH_NODE);
if (searchInf && searchInf->data) {
type = DEBUG_BREAK_SOURCE;
searchData = (nodeSearchDataPtr) searchInf->data;
if (lineNo != NULL)
searchData->lineNo = *lineNo;
searchData->nameInput = (xmlChar *) xmlMemStrdup((char *) *url);
guessStylesheetName(searchInf);
/* try to verify that the line number is valid */
if (searchInf->found) {
/* ok it looks like we've got a valid url */
/* searchData->url will be freed by searchFreeInfo */
if (searchData->absoluteNameMatch)
searchData->url = (xmlChar *)
xmlMemStrdup((char *) searchData->absoluteNameMatch);
else
searchData->url = (xmlChar *)
xmlMemStrdup((char *) searchData->guessedNameMatch);
if (lineNo != NULL) {
/* now to check the line number */
if (searchData->node) {
searchInf->found = 0;
/* searchData->node is set to the topmost node in stylesheet */
walkChildNodes((xmlHashScanner) scanForNode, searchInf,
searchData->node);
if (!searchInf->found) {
xsldbgGenericErrorFunc(i18n("Warning: Breakpoint for file \"%1\" at line %2 does not seem to be valid.\n").arg(xsldbgUrl(*url)).arg(*lineNo));
}
*lineNo = searchData->lineNo;
xmlFree(*url);
*url = xmlStrdup(searchData->url);
result = 1;
}
} else {
/* we've been asked just to check the file name */
if (*url)
xmlFree(*url);
if (searchData->absoluteNameMatch)
*url = (xmlChar *)
xmlMemStrdup((char *) searchData->absoluteNameMatch);
else
*url = (xmlChar *)
xmlMemStrdup((char *) searchData->guessedNameMatch);
result = 1;
}
} else{
xsldbgGenericErrorFunc(i18n("Error: Unable to find a stylesheet file whose name contains %1.\n").arg(xsldbgUrl(*url)));
if (lineNo){
xsldbgGenericErrorFunc(i18n("Warning: Breakpoint for file \"%1\" at line %2 does not seem to be valid.\n").arg(xsldbgUrl(*url)).arg(*lineNo));
}
}
}
if (searchInf)
searchFreeInfo(searchInf);
else
xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
return result;
}
/**
* validateData:
* @url : is valid name of a xml data file
* @lineNo : lineNo >= 0
*
* Returns 1 if a breakpoint could be set at specified file url and line number
* 0 otherwise
*/
int
validateData(xmlChar ** url, long *lineNo)
{
int result = 0;
searchInfoPtr searchInf;
nodeSearchDataPtr searchData = NULL;
char *lastSlash;
if (!filesGetMainDoc()) {
if (!optionsGetIntOption(OPTIONS_GDB)){
xsldbgGenericErrorFunc(i18n("Error: Data file is invalid. Try the run command first.\n"));
}
return result;
}
if (!url) {
#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
xsltGenericError(xsltGenericErrorContext,
"Error: NULL argument provided\n");
#endif
return result;
}
searchInf = searchNewInfo(SEARCH_NODE);
if (searchInf && searchInf->data && filesGetMainDoc()) {
/* Try to verify that the line number is valid.
First try an absolute name match */
searchData = (nodeSearchDataPtr) searchInf->data;
if (lineNo != NULL)
searchData->lineNo = *lineNo;
else
searchData->lineNo = -1;
searchData->url = (xmlChar *) xmlMemStrdup((char *) *url);
walkChildNodes((xmlHashScanner) scanForNode, searchInf,
(xmlNodePtr) filesGetMainDoc());
/* Next try to guess file name by adding the prefix of main document
if no luck so far */
if (!searchInf->found) {
/* Find the last separator of the documents URL */
lastSlash = xmlStrrChr(filesGetMainDoc()->URL, URISEPARATORCHAR);
if (!lastSlash)
lastSlash = xmlStrrChr(filesGetMainDoc()->URL, PATHCHAR);
if (lastSlash) {
lastSlash++;
xmlStrnCpy(buff, filesGetMainDoc()->URL,
lastSlash - (char *) filesGetMainDoc()->URL);
buff[lastSlash - (char *) filesGetMainDoc()->URL] = '\0';
xmlStrCat(buff, *url);
} else
xmlStrCpy(buff, "");
if (xmlStrLen(buff) > 0) {
if (searchData->url)
xmlFree(searchData->url);
searchData->url = (xmlChar *) xmlMemStrdup((char *) buff);
walkChildNodes((xmlHashScanner) scanForNode, searchInf,
(xmlNodePtr) filesGetMainDoc());
}
}
if (!searchInf->found) {
if (lineNo){
xsldbgGenericErrorFunc(i18n("Warning: Breakpoint for file \"%1\" at line %2 does not seem to be valid.\n").arg(xsldbgUrl(*url)).arg(*lineNo));
} else{
xsldbgGenericErrorFunc(i18n("Error: Unable to find a data file whose name contains %1.\n").arg(xsldbgUrl(*url)));
}
result = 1;
} else {
if (*url)
xmlFree(*url);
*url = xmlStrdup(searchData->url);
result = 1;
}
}
if (searchInf)
searchFreeInfo(searchInf);
else
xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
return result;
}
/**
* xslDbgShellBreak:
* @arg: Is valid and in UTF-8
* @style: Is valid
* @ctxt: Is valid
*
* Add break point specified by arg
*
* Returns 1 on success,
* 0 otherwise
*/
int
xslDbgShellBreak(xmlChar * arg, xsltStylesheetPtr style,
xsltTransformContextPtr ctxt)
{
int result = 0;
long lineNo = -1;
xmlChar *url = NULL;
int orphanedBreakPoint = 0;
breakPointPtr breakPtr;
static const char *errorPrompt = I18N_NOOP("Failed to add breakpoint.");
if (style == NULL) {
style = filesGetStylesheet();
}
if (!style || !filesGetMainDoc()) {
if (!optionsGetIntOption(OPTIONS_GDB)){
xsldbgGenericErrorFunc(i18n("Error: Debugger has no files loaded. Try reloading files.\n"));
xsldbgGenericErrorFunc(TQString("Error: %1\n").arg(i18n(errorPrompt)));
return result;
}else{
orphanedBreakPoint = 1;
}
}
if (!arg) {
#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
xsltGenericError(xsltGenericErrorContext,
"Error: NULL argument provided\n");
#endif
return result;
}
if (arg[0] == '-') {
xmlChar *opts[2];
if ((xmlStrLen(arg) > 1) && (arg[1] == 'l')) {
if (splitString(&arg[2], 2, opts) == 2) {
if ((xmlStrlen(opts[1]) == 0) ||
!sscanf((char *) opts[1], "%ld", &lineNo)) {
xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as a line number.\n").arg((char*)opts[1]));
xsldbgGenericErrorFunc(TQString("Error: %1\n").arg(i18n(errorPrompt)));
return result;
} else {
/* try to guess whether we are looking for source or data
* break point
*/
xmlChar *escapedURI;
trimString(opts[0]);
url = filesExpandName(opts[0]);
if (url){
escapedURI = xmlURIEscapeStr(url, (const xmlChar*)"/");
if (escapedURI){
xmlFree(url);
url = escapedURI;
}
}
if (url) {
if (!orphanedBreakPoint){
if (filesIsSourceFile(url)) {
if (validateSource(&url, &lineNo))
result =
breakPointAdd(url, lineNo, NULL, NULL,
DEBUG_BREAK_SOURCE);
} else {
if (validateData(&url, &lineNo))
result =
breakPointAdd(url, lineNo, NULL, NULL,
DEBUG_BREAK_DATA);
}
}else{
if (filesIsSourceFile(url)) {
result =
breakPointAdd(url, lineNo, NULL, NULL,
DEBUG_BREAK_SOURCE);
}else{
result =
breakPointAdd(url, lineNo, NULL, NULL,
DEBUG_BREAK_DATA);
}
breakPtr = breakPointGet(url, lineNo);
if (breakPtr){
breakPtr->flags |= BREAKPOINT_ORPHANED;
}else{
xsldbgGenericErrorFunc(i18n("Error: Unable to find the added breakpoint."));
}
}
}
}
} else
xsldbgGenericErrorFunc(i18n("Error: Invalid arguments to command %1.\n").arg("break"));
}
} else {
/* add breakpoint at specified template names */
xmlChar *opts[2];
xmlChar *name = NULL, *nameURI = NULL, *mode = NULL, *modeURI = NULL;
xmlChar *templateName = NULL, *modeName = NULL;
xmlChar *tempUrl = NULL; /* we must use a non-const xmlChar *
and we are not making a copy
of orginal value so this must not be
freed */
xmlChar *defaultUrl = (xmlChar *) "<n/a>";
int newBreakPoints = 0, validatedBreakPoints = 0;
int allTemplates = 0;
int ignoreTemplateNames = 0;
int argCount;
int found;
xsltTemplatePtr templ;
if (orphanedBreakPoint || !ctxt){
/* Add an orphaned template breakpoint we will need to call this function later to
activate the breakpoint */
result =
breakPointAdd(orphanedTemplateURL, orphanedTemplateLineNo, arg, NULL,
DEBUG_BREAK_SOURCE);
breakPtr = breakPointGet(orphanedTemplateURL, orphanedTemplateLineNo++);
if (breakPtr){
breakPtr->flags |= BREAKPOINT_ORPHANED;
}else{
#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
xsltGenericError(xsltGenericErrorContext,
"Error: Unable to find added breakpoint");
#endif
}
return result;
}
argCount = splitString(arg, 2, opts);
if ((argCount == 2) && (xmlStrLen(opts[1]) == 0))
argCount = 1;
switch (argCount){
case 0:
allTemplates = 1;
break;
case 1:
if (xmlStrEqual(opts[0], (xmlChar*)"*")){
allTemplates = 1;
}else{
if (xmlStrEqual(opts[0], (xmlChar*)"\\*")){
opts[0][0] = '*';
opts[0][1] = '\0';
}
name = xmlSplitQName2(opts[0], &nameURI);
if (name == NULL){
name = xmlStrdup(opts[0]);
}else{
if (nameURI){
/* get the real URI for this namespace */
const xmlChar *temp = xmlXPathNsLookup(ctxt->xpathCtxt, nameURI);
if (temp)
xmlFree(nameURI);
nameURI = xmlStrdup(temp);
}
}
}
break;
case 2:
if (xmlStrLen(opts[0]) == 0){
/* we don't care about the template name ie we are trying to match
templates with a given mode */
ignoreTemplateNames = 1;
}else{
name = xmlSplitQName2(opts[0], &nameURI);
if (name == NULL)
name = xmlStrdup(opts[0]);
if (nameURI){
/* get the real URI for this namespace */
const xmlChar *temp = xmlXPathNsLookup(ctxt->xpathCtxt,
nameURI);
if (temp)
xmlFree(nameURI);
nameURI = xmlStrdup(temp);
}
}
mode = xmlSplitQName2(opts[1], &modeURI);
if (mode == NULL)
mode = xmlStrdup(opts[1]);
if (modeURI){
/* get the real URI for this namespace */
const xmlChar *temp = xmlXPathNsLookup(ctxt->xpathCtxt, modeURI);
if (temp)
xmlFree(modeURI);
modeURI = xmlStrdup(temp);
}
break;
default:
xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for command %1.\n").arg("break"));
return 0;
}
while (style) {
templ = style->templates;
while (templ) {
found = 0;
if (templ->elem && templ->elem->doc
&& templ->elem->doc->URL) {
tempUrl = (xmlChar *) templ->elem->doc->URL;
} else {
tempUrl = defaultUrl;
}
if (templ->match)
templateName = xmlStrdup(templ->match);
else
templateName = fullQName(templ->nameURI, templ->name);
if (allTemplates)
found = 1;
else {
if (ignoreTemplateNames){
if (!mode || (xmlStrEqual(templ->mode, mode) &&
(!modeURI || xmlStrEqual(templ->modeURI,
modeURI))))
found = 1;
} else if (templ->match){
if ((xmlStrEqual(templ->match, name) &&
(!modeURI || xmlStrEqual(templ->modeURI,
modeURI)) &&
(!mode || xmlStrEqual(templ->mode,
mode))))
found = 1;
}else{
if(xmlStrEqual(templ->name, name) &&
(!nameURI || xmlStrEqual(templ->nameURI, nameURI)))
found = 1;
}
}
if (found) {
int templateLineNo = xmlGetLineNo(templ->elem);
breakPointPtr searchPtr = breakPointGet(tempUrl, templateLineNo);
if (templ->mode)
modeName =
fullQName(templ->modeURI, templ->mode);
if (!searchPtr){
if (breakPointAdd(tempUrl, templateLineNo,
templateName, modeName,
DEBUG_BREAK_SOURCE)){
newBreakPoints++;
}
}else{
if ((templateLineNo != searchPtr->lineNo ) || !xmlStrEqual(tempUrl, searchPtr->url)){
int lastId = searchPtr->id;
int lastCounter = breakPointCounter;
/* we have a new location for breakpoint */
if (breakPointDelete(searchPtr)){
if (breakPointAdd(tempUrl, templateLineNo, templateName, modeName,DEBUG_BREAK_SOURCE)){
searchPtr = breakPointGet(tempUrl, templateLineNo);
if (searchPtr){
searchPtr->id = lastId;
result = 1;
breakPointCounter = lastCounter;
xsldbgGenericErrorFunc(i18n("Information: Breakpoint validation has caused breakpoint %1 to be re-created.\n").arg(searchPtr->id));
validatedBreakPoints++;
}
}
}
}else{
if (xsldbgValidateBreakpoints != BREAKPOINTS_BEING_VALIDATED){
xsldbgGenericErrorFunc(i18n("Warning: Breakpoint exits for file \"%1\" at line %2.\n").arg(xsldbgUrl(tempUrl)).arg(templateLineNo));
}
validatedBreakPoints++;
}
}
}
if (templateName){
xmlFree(templateName);
templateName = NULL;
}
if (modeName){
xmlFree(modeName);
modeName = NULL;
}
templ = templ->next;
}
if (style->next)
style = style->next;
else
style = style->imports;
}
if ((newBreakPoints == 0) && (validatedBreakPoints == 0)) {
xsldbgGenericErrorFunc(i18n("Error: No templates found or unable to add breakpoint.\n"));
url = NULL; /* flag that we've printed partial error message about the problem url */
} else {
result = 1;
if (newBreakPoints){
xsldbgGenericErrorFunc(i18n("Information: Added %n new breakpoint.", "Information: Added %n new breakpoints.", newBreakPoints) + TQString("\n"));
}
}
if (name)
xmlFree(name);
if (nameURI)
xmlFree(nameURI);
if (mode)
xmlFree(mode);
if (modeURI)
xmlFree(modeURI);
if (defaultUrl && !xmlStrEqual((xmlChar*)"<n/a>", defaultUrl))
xmlFree(defaultUrl);
if (tempUrl)
url = xmlStrdup(tempUrl);
} /* end add template breakpoints */
if (!result) {
if (url)
xsldbgGenericErrorFunc(i18n("Error: Failed to add breakpoint for file \"%1\" at line %2.\n").arg(xsldbgUrl(url)).arg(lineNo));
else
xsldbgGenericErrorFunc(i18n("Error: Failed to add breakpoint.\n"));
}
if (url)
xmlFree(url);
return result;
}
/**
* xslDbgShellDelete:
* @arg: Is valid and in UTF-8
*
* Delete break point specified by arg
*
* Returns 1 on success,
* 0 otherwise
*/
int
xslDbgShellDelete(xmlChar * arg)
{
int result = 0, breakPointId;
long lineNo;
breakPointPtr breakPtr = NULL;
static const char *errorPrompt = I18N_NOOP("Failed to delete breakpoint.");
if (!arg) {
#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
xsltGenericError(xsltGenericErrorContext,
"Error: NULL argument provided\n");
#endif
xsldbgGenericErrorFunc(TQString("Error: %1\n").arg(i18n(errorPrompt)));
return result;
}
if (arg[0] == '-') {
xmlChar *opts[2], *url = NULL;
if ((xmlStrLen(arg) > 1) && (arg[1] == 'l')) {
if (splitString(&arg[2], 2, opts) == 2) {
if ((xmlStrlen(opts[1]) == 0) ||
!sscanf((char *) opts[1], "%ld", &lineNo)) {
xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as a line number.\n").arg((char*)opts[1]));
} else {
xmlChar *escapedURI;
trimString(opts[0]);
url = filesExpandName(opts[0]);
if (url){
escapedURI = xmlURIEscapeStr(url, (const xmlChar*)"/");
if (escapedURI){
xmlFree(url);
url = escapedURI;
}
}
if (url) {
if (filesIsSourceFile(url)) {
if (validateSource(&url, &lineNo))
breakPtr = breakPointGet(url, lineNo);
} else if (validateData(&url, &lineNo))
breakPtr = breakPointGet(url, lineNo);
if (!breakPtr || !breakPointDelete(breakPtr)){
xsldbgGenericErrorFunc(i18n("Error: Breakpoint does not exist for file \"%1\" at line %2.\n").arg(xsldbgUrl(url)).arg(lineNo));
}else{
result = 1;
}
xmlFree(url);
}
}
} else{
xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for command %1.\n").arg("delete"));
}
}
} else if (xmlStrEqual((xmlChar*)"*", arg)) {
result = 1;
/*remove all from breakpoints */
breakPointEmpty();
} else if (sscanf((char *) arg, "%d", &breakPointId)) {
breakPtr = findBreakPointById(breakPointId);
if (breakPtr) {
result = breakPointDelete(breakPtr);
if (!result) {
xsldbgGenericErrorFunc(i18n("Error: Unable to delete breakpoint %1.\n").arg(breakPointId));
}
} else {
xsldbgGenericErrorFunc(i18n("Error: Breakpoint %1 does not exist.\n").arg(breakPointId));
}
} else {
breakPtr = findBreakPointByName(arg);
if (breakPtr) {
result = breakPointDelete(breakPtr);
if (!result) {
xsldbgGenericErrorFunc(i18n("Error: Unable to delete breakpoint at template %1.\n").arg(xsldbgText(arg)));
}
} else{
xsldbgGenericErrorFunc(i18n("Error: Breakpoint at template \"%1\" does not exist.\n").arg(xsldbgText(arg)));
}
}
if (!result)
xsldbgGenericErrorFunc(TQString("Error: %1\n").arg(i18n(errorPrompt)));
return result;
}
/**
* xslDbgShellEnableBreakPoint:
* @payload: A valid breakPointPtr
* @data: Enable type, a pointer to an integer
* for a value of
* 1 enable break point
* 0 disable break point
* -1 toggle enabling of break point
* @name: Not used
*
* Enable/disable break points via use of scan of break points
*/
void
xslDbgShellEnableBreakPoint(void *payload, void *data,
xmlChar * name)
{
Q_UNUSED(name);
if (payload && data) {
breakPointEnable((breakPointPtr) payload, *(int *) data);
}
}
/**
* xslDbgShellEnable:
* @arg : is valid and in UTF-8
* @enableType : enable break point if 1, disable if 0, toggle if -1
*
* Enable/disable break point specified by arg using enable
* type of @enableType
* Returns 1 if successful,
* 0 otherwise
*/
int
xslDbgShellEnable(xmlChar * arg, int enableType)
{
int result = 0, breakPointId;
long lineNo;
breakPointPtr breakPtr = NULL;
static const char *errorPrompt = I18N_NOOP("Failed to enable/disable breakpoint.");
if (!filesGetStylesheet() || !filesGetMainDoc()) {
xsldbgGenericErrorFunc(i18n("Error: Debugger has no files loaded. Try reloading files.\n"));
xsldbgGenericErrorFunc(TQString("Error: %1\n").arg(i18n(errorPrompt)));
return result;
}
if (!arg) {
#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
xsltGenericError(xsltGenericErrorContext,
"Error: NULL argument provided\n");
#endif
xsldbgGenericErrorFunc(TQString("Error: %1\n").arg(i18n(errorPrompt)));
return result;
}
if (arg[0] == '-') {
xmlChar *opts[2], *url = NULL;
if ((xmlStrLen(arg) > 1) && (arg[1] == 'l')) {
if (splitString(&arg[2], 2, opts) == 2) {
if ((xmlStrlen(opts[1]) == 0) ||
!sscanf((char *) opts[1], "%ld", &lineNo)) {
xsldbgGenericErrorFunc(i18n("Error: Unable to parse %1 as a line number.\n").arg((char*)opts[1]));
} else {
xmlChar *escapedURI;
trimString(opts[0]);
url = filesExpandName(opts[0]);
if (url){
escapedURI = xmlURIEscapeStr(url, (const xmlChar*)"/");
if (escapedURI){
xmlFree(url);
url = escapedURI;
}
}
if (url) {
if (strstr((char *) url, ".xsl")) {
if (validateSource(&url, NULL))
breakPtr = breakPointGet(url, lineNo);
} else if (validateData(&url, NULL))
breakPtr = breakPointGet(url, lineNo);
if (breakPtr){
result = breakPointEnable(breakPtr, enableType);
}else{
xsldbgGenericErrorFunc(i18n("Error: Breakpoint does not exist for file \"%1\" at line %2.\n").arg(xsldbgUrl(url)).arg(lineNo));
}
xmlFree(url);
}
}
} else
xsldbgGenericErrorFunc(i18n("Error: Invalid arguments for command %1.\n").arg("enable"));
}
} else if (xmlStrEqual((xmlChar*)"*", arg)) {
result = 1;
/*enable/disable all from breakpoints */
walkBreakPoints((xmlHashScanner) xslDbgShellEnableBreakPoint,
&enableType);
} else if (sscanf((char *) arg, "%d", &breakPointId)) {
breakPtr = findBreakPointById(breakPointId);
if (breakPtr) {
result = breakPointEnable(breakPtr, enableType);
if (!result) {
xsldbgGenericErrorFunc(i18n("Error: Unable to enable/disable breakpoint %1.\n").arg(breakPointId));
}
} else {
xsldbgGenericErrorFunc(i18n("Error: Breakpoint %1 does not exist.\n").arg(breakPointId));
}
} else {
breakPtr = findBreakPointByName(arg);
if (breakPtr) {
result = breakPointEnable(breakPtr, enableType);
} else
xsldbgGenericErrorFunc(i18n("Error: Breakpoint at template \"%1\" does not exist.\n").arg(xsldbgText(arg)));
}
if (!result)
xsldbgGenericErrorFunc(TQString("Error: %1\n").arg(i18n(errorPrompt)));
return result;
}
/**
* xslDbgShellPrintBreakPoint:
* @payload: A valid breakPointPtr
* @data: Not used
* @name: Not used
*
* Print data given by scan of break points
*/
void
xslDbgShellPrintBreakPoint(void *payload, void *data,
xmlChar * name)
{
Q_UNUSED(data);
Q_UNUSED(name);
if (payload) {
if (getThreadStatus() == XSLDBG_MSG_THREAD_RUN) {
notifyListQueue(payload);
} else {
printCount++;
xsldbgGenericErrorFunc(" ");
breakPointPrint((breakPointPtr) payload);
xsldbgGenericErrorFunc("\n");
}
}
}
/* Validiate a breakpoint at a given URL and line number
breakPtr and copy must be valid
*/
static int validateBreakPoint(breakPointPtr breakPtr, breakPointPtr copy)
{
int result = 0;
if (!breakPtr || !copy){
#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
xsltGenericError(xsltGenericErrorContext,
"Warning: NULL arguments passed to validateBreakPoint\n");
#endif
return result;
}
if (filesIsSourceFile(breakPtr->url)) {
result = validateSource(©->url, ©->lineNo);
} else {
result = validateData(©->url, ©->lineNo);
}
if (result)
breakPtr->flags &= BREAKPOINT_ALLFLAGS ^ BREAKPOINT_ORPHANED;
else
breakPtr->flags |= BREAKPOINT_ORPHANED;
if ( breakPtr->flags & BREAKPOINT_ORPHANED){
xsldbgGenericErrorFunc(TQString("Warning: Breakpoint %1 is orphaned. Result: %2. Old flags: %3. New flags: %4.\n").arg(breakPtr->id).arg(result).arg(copy->flags).arg(breakPtr->flags));
}
if (!(breakPtr->flags & BREAKPOINT_ORPHANED) && ((copy->lineNo != breakPtr->lineNo ) ||
(xmlStrlen(copy->url) != xmlStrlen(breakPtr->url)) || xmlStrCmp(copy->url, breakPtr->url))){
/* we have a new location for breakpoint */
int lastCounter = breakPointCounter;
copy->templateName = xmlStrdup(breakPtr->templateName);
copy->modeName = xmlStrdup(breakPtr->modeName);
if (breakPointDelete(breakPtr) && !breakPointGet(copy->url, copy->lineNo)){
if (breakPointAdd(copy->url, copy->lineNo, NULL, NULL, copy->type)){
breakPtr = breakPointGet(copy->url, copy->lineNo);
if (breakPtr){
breakPtr->id = copy->id;
breakPtr->flags = copy->flags;
breakPointCounter = lastCounter; /* compensate for breakPointAdd which always
increments the breakPoint counter */
result = 1;
xsldbgGenericErrorFunc(i18n("Information: Breakpoint validation has caused breakpoint %1 to be re-created.\n").arg(breakPtr->id));
}
}
if (!result){
xsldbgGenericErrorFunc(i18n("Warning: Validation of breakpoint %1 failed.\n").arg(copy->id));
}
}
}
return result;
}
/* Validiate a breakpoint at a given URL and line number
breakPtr, copy and ctx must be valid
*/
static int validateTemplateBreakPoint(breakPointPtr breakPtr, breakPointPtr copy, xsltTransformContextPtr ctxt)
{
int result = 0;
if (!breakPtr || !copy || !ctxt){
#ifdef WITH_XSLDBG_DEBUG_BREAKPOINTS
xsltGenericError(xsltGenericErrorContext,
"Warning: NULL arguments passed to validateTemplateBreakPoint\n");
#endif
return result;
}
copy->templateName = xmlStrdup(breakPtr->templateName);
if ((xmlStrlen(copy->templateName) == 0) || xmlStrEqual(copy->templateName, (xmlChar*)"*")){
if (xmlStrEqual(breakPtr->url, orphanedTemplateURL))
breakPointDelete(breakPtr);
if ( xslDbgShellBreak(copy->templateName, NULL, ctxt)){
result = 1;
xsldbgGenericErrorFunc(i18n("Information: Breakpoint validation has caused one or more breakpoints to be re-created.\n"));
}
}else{
if (xmlStrEqual(breakPtr->url, orphanedTemplateURL))
breakPointDelete(breakPtr);
if (xslDbgShellBreak(copy->templateName, NULL, ctxt)){
result = 1;
}
}
xmlFree(copy->templateName);
if (!result){
xsldbgGenericErrorFunc(i18n("Warning: Validation of breakpoint %1 failed.\n").arg(copy->id));
}
return result;
}
/**
* xslDbgShellValidateBreakPoint:
* @payload: A valid breakPointPtr
* @data: Not used
* @name: Not used
*
* Print an warning if a breakpoint is invalid
*/
void xslDbgShellValidateBreakPoint(void *payload, void *data,
xmlChar * name)
{
Q_UNUSED(name);
int result = 0;
if (payload){
breakPointPtr breakPtr = (breakPointPtr) payload;
breakPoint copy; /* create a copy of the breakpoint */
copy.lineNo = breakPtr->lineNo;
copy.url = xmlStrdup(breakPtr->url);
copy.flags = breakPtr->flags;
copy.type = breakPtr->type;
copy.id = breakPtr->id;
if (copy.url){
if (breakPtr->templateName){
/* template name is used to contain the rules to add template breakpoint */
result = validateTemplateBreakPoint(breakPtr, ©, (xsltTransformContextPtr)data);
}else{
result = validateBreakPoint(breakPtr, ©);
}
}else{
xsldbgGenericErrorFunc(i18n("Error: Out of memory.\n"));
}
xmlFree(copy.url);
}
}
|