~pac72/ubuntu/lucid/ddd/devel

« back to all changes in this revision

Viewing changes to ddd/PosBuffer.C

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Schepler
  • Date: 2004-07-22 03:49:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040722034937-cysl08t1jvba4jrx
Tags: 1:3.3.9-3
USERINFO has been renamed to USERINFO.txt; adjust debian/rules code
to match, to get correct information on the About DDD dialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: PosBuffer.C,v 1.94 2001/01/16 08:47:55 zeller Exp $
 
1
// $Id$
2
2
// Filter position information from GDB output.
3
3
 
4
4
// Copyright (C) 1995-1999 Technische Universitaet Braunschweig, Germany.
29
29
// or send a mail to the DDD developers <ddd@gnu.org>.
30
30
 
31
31
char PosBuffer_rcsid[] =
32
 
    "$Id: PosBuffer.C,v 1.94 2001/01/16 08:47:55 zeller Exp $";
33
 
 
34
 
#ifdef __GNUG__
35
 
#pragma implementation
36
 
#endif
 
32
    "$Id$";
37
33
 
38
34
// Misc includes
39
35
#include "assert.h"
60
56
 
61
57
// Filter all lines from ANSWER beginning with LINE.  This is required
62
58
// to suppress the line number output after a `stopping in' message.
63
 
void PosBuffer::filter_line(string& answer)
 
59
void PosBuffer::filter_line(string& answer) const
64
60
{
65
61
    if (already_read != PosComplete)
66
62
        return;
93
89
// Store first address in ANSWER after INDEX in BUFFER
94
90
static void fetch_address(const string& answer, int index, string& buffer)
95
91
{
96
 
    if (buffer != "")
 
92
    if (!buffer.empty())
97
93
        return;                 // Already have an address
98
94
 
99
95
    while (index < int(answer.length()) && !is_address_start(answer[index]))
114
110
static void fetch_function(const string& answer, int index, string& buffer,
115
111
                           bool in_required = false)
116
112
{
117
 
    if (buffer != "")
 
113
    if (!buffer.empty())
118
114
        return;                 // Already have a function
119
115
 
120
116
    string line = answer.from(index);
128
124
    int ws_index = line.index(' ', -1) + 1;
129
125
    line = line.from(ws_index);
130
126
    strip_leading_space(line);
131
 
    if (line != "" && line.contains(rxidentifier, 0))
 
127
    if (!line.empty() && line.contains(rxidentifier, 0))
132
128
        buffer = line;
133
129
}
134
130
 
149
145
    // Check program state
150
146
    switch (gdb->type())
151
147
    {
 
148
    case BASH:
152
149
    case GDB:
153
150
    {
154
151
        // If GDB prints a "Current function" line, it overrides whatever
155
152
        // came before (e.g. "stopped in").
156
153
        if (has_prefix(answer, "Current function is "))
157
 
            already_read = Null;
 
154
            already_read= Null;
158
155
 
159
156
        // Check program state
160
157
        if (has_prefix(answer, "Starting program: "))
185
182
    }
186
183
    break;
187
184
 
 
185
    case DBG:
 
186
    {
 
187
        // Check program state
 
188
        if (has_prefix(answer, "Starting program: "))
 
189
            started = true;
 
190
    }
 
191
    break;
 
192
 
188
193
    case DBX:
189
194
    {
190
195
        if (has_prefix(answer, "Running: "))
197
202
            signaled = true;
198
203
    }
199
204
    break;
200
 
    
 
205
 
 
206
    case PERL:
 
207
    {
 
208
        if (has_prefix(answer, "Loading DB routines from perl5db.pl"))
 
209
          recompiled = true;
 
210
    }
 
211
    break;
 
212
 
201
213
    case XDB:
202
214
    case JDB:
203
215
    case PYDB:
204
 
    case PERL:
205
216
        break;                  // Nothing special
206
217
    }
207
218
 
235
246
 
236
247
        string pfx = app_data.auto_command_prefix;
237
248
 
238
 
        if (auto_cmd_buffer != "" && !auto_cmd_buffer.contains('\n', -1))
 
249
        if (!auto_cmd_buffer.empty() && !auto_cmd_buffer.contains('\n', -1))
239
250
        {
240
251
            // Complete pending auto command
241
252
            if (answer.contains('\n'))
311
322
        case PERL:
312
323
            filter_perl(answer);
313
324
            break;
 
325
 
 
326
        case BASH:
 
327
            filter_bash(answer);
 
328
            break;
 
329
        
 
330
        case DBG:
 
331
            filter_dbg(answer);
 
332
            break;
314
333
        }
315
334
 
316
335
        filter_line(answer);
324
343
{
325
344
    // Try to find out current PC even for non-existent source
326
345
 
327
 
    if (check_pc && pc_buffer == "")
 
346
    if (check_pc && pc_buffer.empty())
328
347
    {
329
348
        // `$pc = ADDRESS'
330
349
#if RUNTIME_REGEX
351
370
        }
352
371
    }
353
372
            
354
 
    if (check_pc && pc_buffer == "" || 
355
 
        check_func && func_buffer == "")
 
373
    if (check_pc && pc_buffer.empty() || 
 
374
        check_func && func_buffer.empty())
356
375
    {
357
376
        // `Breakpoint N, ADDRESS in FUNCTION (ARGS...)'
358
377
#if RUNTIME_REGEX
369
388
        }
370
389
    }
371
390
            
372
 
    if (check_pc && pc_buffer == "" || 
373
 
        check_func && func_buffer == "")
 
391
    if (check_pc && pc_buffer.empty() || 
 
392
        check_func && func_buffer.empty())
374
393
    {
375
394
        // `#FRAME ADDRESS in FUNCTION (ARGS...)'
376
395
#if RUNTIME_REGEX
387
406
        }
388
407
    }
389
408
            
390
 
    if (check_pc && pc_buffer == "" || 
391
 
        check_func && func_buffer == "")
 
409
    if (check_pc && pc_buffer.empty() || 
 
410
        check_func && func_buffer.empty())
392
411
    {
393
412
        // `No line number available for 
394
413
        // address ADDRESS <FUNCTION>'
401
420
        {
402
421
            pc_index = answer.index(' ');
403
422
            fetch_address(answer, pc_index, pc_buffer);
404
 
            if (func_buffer == "")
 
423
            if (func_buffer.empty())
405
424
            {
406
425
                string line = answer.from(pc_index);
407
426
                line = line.after('<');
408
427
                line = line.before('>');
409
 
                if (line != "")
 
428
                if (!line.empty())
410
429
                    func_buffer = line;
411
430
            }
412
431
        }
413
432
    }
414
433
 
415
 
    if (check_pc && pc_buffer == "" && answer != "")
 
434
    if (check_pc && pc_buffer.empty() && !answer.empty())
416
435
    {
417
436
        // `ADDRESS in FUNCTION'
418
437
#if RUNTIME_REGEX
441
460
 
442
461
    // Try to find out current function name, even for
443
462
    // non-existing addresses
444
 
    if (check_func && func_buffer == "")
 
463
    if (check_func && func_buffer.empty())
445
464
    {
446
465
        // `Breakpoint N, FUNCTION (ARGS...)'
447
466
        // This regex used for PYDB as well.
453
472
            fetch_function(answer, bp_index, func_buffer);
454
473
    }
455
474
 
456
 
    if (check_func && func_buffer == "")
 
475
    if (check_func && func_buffer.empty())
457
476
    {
458
477
        // `#FRAME FUNCTION'
459
478
#if RUNTIME_REGEX
467
486
        }
468
487
    }
469
488
 
470
 
    if (check_func && func_buffer == "")
 
489
    if (check_func && func_buffer.empty())
471
490
    {
472
491
        // FUNCTION (ARGS...) at FILE:POS
473
492
        int at_index = answer.index(" at ");
531
550
        // which is the output of an 'info line' command
532
551
        string line = answer.after("Line ");
533
552
        string file = answer.after('\"');
534
 
        if (line != "" && file != "")
 
553
        if (!line.empty() && !file.empty())
535
554
        {
536
555
            line = line.before(" of");
537
556
            file = file.before('\"') + ":" + line;
538
 
            if (line != "" && file != "")
 
557
            if (!line.empty() && !file.empty())
539
558
            {
540
559
                pos_buffer = file;
541
560
                already_read = PosComplete;
555
574
            // Try to construct position from `at FILE:POS' (vxworks)
556
575
            string file = answer.after(" at ");
557
576
            file = file.before('\n');
558
 
            if (file != "")
 
577
            if (!file.empty())
559
578
            {
560
579
                pos_buffer = file;
561
580
                already_read = PosComplete;
598
617
    pc_buffer = pc_buffer.through(rxaddress);
599
618
 
600
619
    answer.at(index1, index2 - index1 + 1) = "";
601
 
    if (pos_buffer != "")
 
620
    if (!pos_buffer.empty())
602
621
        already_read = PosComplete;
603
622
}
604
623
 
618
637
        string ans = answer;
619
638
        int num = read_positive_nr(ans);
620
639
        string pos = source_view->bp_pos(num);
621
 
        if (pos != "")
 
640
        if (!pos.empty())
622
641
        {
623
642
            file = pos.before(':');
624
643
            line = pos.after(':');
670
689
        file = answer.after('\"');
671
690
        file = file.before('\"');
672
691
 
673
 
        if (line != "")
 
692
        if (!line.empty())
674
693
        {
675
694
            already_read = PosComplete;
676
695
            // answer = answer.after("\n");
699
718
                line = line.after("::");
700
719
            line = line.after(":");
701
720
            line = line.through(rxint);
702
 
            if (line != "")
 
721
            if (!line.empty())
703
722
            {
704
723
                if (answer.index('\n', dbxpos_index) >= 0)
705
724
                {
774
793
            func_buffer = func;
775
794
        }
776
795
 
777
 
        if (func_buffer != "")
 
796
        if (!func_buffer.empty())
778
797
        {
779
798
            // With DEC's `ladebug', the function name is fully qualified,
780
799
            // as in `stopped at [void tree_test(void):277 0x120003f44]'
788
807
                func_buffer = func_buffer.after(' ');
789
808
        }
790
809
 
791
 
        if (line == "")
 
810
        if (line.empty())
792
811
        {
793
812
            line = answer.after("at line ", stopped_index);
794
813
            line = line.through(rxint);
795
 
            if ((file != "" || func_buffer != "") &&
 
814
            if ((!file.empty() || !func_buffer.empty()) &&
796
815
                !answer.contains("at line "))
797
816
                line = "0";
798
817
        }
799
818
 
800
 
        if (line != "")
 
819
        if (!line.empty())
801
820
            already_read = PosComplete;
802
821
    }
803
822
 
819
838
        if (line.contains(rxint, 0))
820
839
        {
821
840
            line = line.through(rxint);
822
 
            if (line != "")
 
841
            if (!line.empty())
823
842
            {
824
843
                if (answer.contains('\n'))
825
844
                {
844
863
    {
845
864
        // Up/Down command entered
846
865
        string nr = answer.after("\n");
847
 
        if (nr != "")
 
866
        if (!nr.empty())
848
867
        {
849
868
            line = itostring(atoi(nr.chars()));
850
869
            already_read = PosComplete;
875
894
        return;
876
895
    }
877
896
 
878
 
    if (already_read == PosComplete && line != "")
 
897
    if (already_read == PosComplete && !line.empty())
879
898
    {
880
 
        if (file != "")
 
899
        if (!file.empty())
881
900
            pos_buffer = file + ":" + line;
882
901
        else
883
902
            pos_buffer = line;
884
903
    }
885
904
 
886
 
    if (already_read == PosComplete && pos_buffer == "")
 
905
    if (already_read == PosComplete && pos_buffer.empty())
887
906
        already_read = Null;
888
907
}
889
908
 
901
920
 
902
921
    // INDEX points at the start of a line
903
922
    int index = 0;
904
 
    while (index >= 0 && answer != "")
 
923
    while (index >= 0 && !answer.empty())
905
924
    {
906
925
        string line = answer.from(index);
907
926
        if (line.contains('\n'))
977
996
    }
978
997
 
979
998
    int index = 0;
980
 
    while (index >= 0 && answer != "")
 
999
    while (index >= 0 && !answer.empty())
981
1000
    {
982
1001
        string line = answer.from(index);
983
1002
        if (line.contains('\n'))
1025
1044
                    // Strip method
1026
1045
                    class_name = class_name.before('.', -1);
1027
1046
 
1028
 
                    if (class_name.contains("." + file), -1)
 
1047
                    if (class_name.contains("." + file))
1029
1048
                    {
1030
1049
                        // CLASS_NAME is more qualified - use it
1031
1050
                        file = class_name;
1137
1156
    }
1138
1157
}
1139
1158
 
 
1159
void PosBuffer::filter_dbg(string& answer)
 
1160
{
 
1161
    int idx1, idx2;
 
1162
    
 
1163
    if (already_read != PosComplete && !answer.contains('\n'))
 
1164
    {
 
1165
        // Position info is incomplete
 
1166
        answer_buffer = answer;
 
1167
        answer = "";
 
1168
        already_read = PosPart;
 
1169
        return;
 
1170
    }
 
1171
 
 
1172
    idx1 = 0;
 
1173
    while (idx1 < (int)answer.length())
 
1174
    {
 
1175
        idx2 = answer.index('\n', idx1);
 
1176
        if (idx2 < 0) idx2 = answer.length();   
 
1177
        string line = answer.at(idx1, idx2 - idx1);
 
1178
        if (line.contains('\n'))
 
1179
            line = line.before('\n');
 
1180
        strip_trailing_space(line);
 
1181
                
 
1182
        // DBG uses a format like `test.php:4 <main>\n echo $a."hello world."'
 
1183
#if RUNTIME_REGEX
 
1184
        static regex rxdbgpos("[^ \t]*:[ \t]*[1-9][0-9]*[ \t]*<.*>");
 
1185
        static regex rxdbgframepos("#[0-9]*[ \t]*<.*>[ \t]*at[ \t]*[^ \t]*:[ \t]*[1-9][0-9]*");
 
1186
#endif
 
1187
        if (line.matches(rxdbgpos)) 
 
1188
        {
 
1189
            string file = line.before(':');
 
1190
            line = line.after(':');
 
1191
                    
 
1192
            string line_no = line;
 
1193
            strip_leading_space(line_no);
 
1194
            line_no = line_no.before(' ');
 
1195
            
 
1196
            line = line.after('<');
 
1197
            func_buffer  = line.before('>');
 
1198
            strip_leading_space(func_buffer);
 
1199
                    
 
1200
            pos_buffer   = file + ":" + line_no;
 
1201
            
 
1202
            // Delete this line from output
 
1203
            answer.at(idx1, idx2 - idx1 + 1) = "";
 
1204
            already_read = PosComplete;
 
1205
            break;
 
1206
 
 
1207
        } else if (line.matches(rxdbgframepos)) 
 
1208
        {
 
1209
            string addr = line.before(">");
 
1210
            func_buffer = addr.after('<');
 
1211
            strip_leading_space(func_buffer);
 
1212
            
 
1213
            string file = line.after(">");
 
1214
            file = file.after("at");
 
1215
            strip_leading_space(file);
 
1216
            
 
1217
            string line_no = file.after(':');
 
1218
            strip_leading_space(line_no);
 
1219
        
 
1220
            file = file.before(':');
 
1221
                    
 
1222
            pos_buffer   = file + ":" + line_no;
 
1223
            
 
1224
            // Delete this line from output
 
1225
            answer.at(idx1, idx2 - idx1 + 1) = "";
 
1226
            already_read = PosComplete;
 
1227
            break;
 
1228
        }
 
1229
        
 
1230
        idx1 = idx2+1;
 
1231
    }
 
1232
}
 
1233
        
1140
1234
void PosBuffer::filter_perl(string& answer)
1141
1235
{
1142
1236
    // Check for regular source info
1184
1278
 
1185
1279
        // INDEX points at the start of a line
1186
1280
        int index = 0;
1187
 
        while (index >= 0 && answer != "")
 
1281
        while (index >= 0 && !answer.empty())
1188
1282
        {
1189
1283
            string line = answer.from(index);
1190
1284
            if (line.contains('\n'))
1221
1315
    }
1222
1316
}
1223
1317
 
 
1318
void PosBuffer::filter_bash(string& answer)
 
1319
{
 
1320
    // Check for regular source info
 
1321
    int index1 = answer.index ("\032\032");
 
1322
            
 
1323
    if (index1 < 0) 
 
1324
    {
 
1325
        int index_p = answer.index ("\032");
 
1326
        if (index_p >= 0 && index_p == int(answer.length()) - 1)
 
1327
        {
 
1328
            // Possible begin of position info at end of ANSWER
 
1329
            answer_buffer = "\032";
 
1330
            answer = answer.before (index_p);
 
1331
            already_read = PosPart;
 
1332
            return;
 
1333
        }
 
1334
    }
 
1335
    else
 
1336
    {
 
1337
        // ANSWER contains position info
 
1338
        int index2 = answer.index("\n", index1);
 
1339
            
 
1340
        if (index2 == -1)
 
1341
        {
 
1342
            // Position info is incomplete
 
1343
            answer_buffer = answer.from (index1);
 
1344
            answer = answer.before (index1);
 
1345
            already_read = PosPart;
 
1346
            return;
 
1347
        }
 
1348
        else
 
1349
        {
 
1350
            assert (index1 < index2);
 
1351
            
 
1352
            // Position info is complete
 
1353
            already_read = PosComplete;
 
1354
            pos_buffer = answer.at(index1 + 2, index2 - (index1 + 2));
 
1355
            answer.at(index1, index2 - index1 + 1) = "";
 
1356
        }
 
1357
    }
 
1358
 
 
1359
    if (already_read != PosComplete)
 
1360
    {
 
1361
        // Try '(FILE:LINE):\n';
 
1362
 
 
1363
        // INDEX points at the start of a line
 
1364
        int index = 0;
 
1365
        while (index >= 0 && !answer.empty())
 
1366
        {
 
1367
            string line = answer.from(index);
 
1368
            if (line.contains('\n'))
 
1369
                line = line.before('\n');
 
1370
            strip_trailing_space(line);
 
1371
                    
 
1372
#if RUNTIME_REGEX
 
1373
            static regex rxbashpos("[(][^:]*:[1-9][0-9]*[)]:");
 
1374
#endif
 
1375
            if (line.matches(rxbashpos))
 
1376
            {
 
1377
                // Fetch position
 
1378
                pos_buffer = line.after('(');
 
1379
                pos_buffer = pos_buffer.before(')');
 
1380
                already_read = PosComplete;
 
1381
 
 
1382
                // Delete this line from output
 
1383
                int next_index = answer.index('\n', index);
 
1384
                if (next_index < 0)
 
1385
                    next_index = answer.length();
 
1386
                else
 
1387
                    next_index++;
 
1388
                answer.at(index, next_index - index) = "";
 
1389
                break;
 
1390
            }
 
1391
            else
 
1392
            {
 
1393
                // Look at next line
 
1394
                index = answer.index('\n', index);
 
1395
                if (index >= 0)
 
1396
                    index++;
 
1397
            }
 
1398
        }
 
1399
    }
 
1400
}
 
1401
 
1224
1402
string PosBuffer::answer_ended ()
1225
1403
{
1226
1404
    switch (already_read) 
1227
1405
    {
1228
1406
    case Null:
1229
1407
    {
1230
 
        assert (pos_buffer == "");
 
1408
        assert (pos_buffer.empty());
1231
1409
        return auto_cmd_part;
1232
1410
    }
1233
1411
 
1234
1412
    case PosPart:
1235
1413
    {
1236
 
        assert (pos_buffer == "");
1237
 
        string ans = answer_buffer;
 
1414
        assert (pos_buffer.empty());
 
1415
        const string ans = auto_cmd_part + answer_buffer;
1238
1416
        answer_buffer = "";
1239
 
        return auto_cmd_part + ans;
 
1417
        return ans;
1240
1418
    }
1241
1419
 
1242
1420
    case PosComplete:
1243
1421
    {
1244
 
        assert (pos_buffer != "");
 
1422
        assert (!pos_buffer.empty());
1245
1423
        return auto_cmd_part;
1246
1424
    }
1247
1425
 
1248
1426
    default:
1249
1427
    {
1250
1428
        assert(0);              // This can't happen
 
1429
        ::abort();
1251
1430
        break;
1252
1431
    }
1253
1432
    }