aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/call-ar-st.exp
blob: 21df59d6b31e5985352d800fb8707904f1bda92e (plain)
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
#   Copyright 1998-2013 Free Software Foundation, Inc.

# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file was written by Elena Zannoni (ezannoni@cygnus.com)



standard_testfile

# Test depends on printf, which the sparclet stub doesn't support.  
if { [istarget "sparclet-*-*"] } {
    return 0
}

# Some targets can't call functions, so don't even bother with this
# test.
if [target_info exists gdb,cannot_call_functions] {
    setup_xfail "*-*-*" 2416
    fail "This target can not call functions"
    continue
}

# Create and source the file that provides information about the compiler
# used to compile the test case.

if [get_compiler_info] {
    return -1
}

if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
    untested $testfile.exp
    return -1
}


set oldtimeout $timeout
set timeout [expr "$timeout + 60"]

gdb_test_no_output "set print sevenbit-strings"
gdb_test_no_output "set print address off"
gdb_test_no_output "set width 0"


if ![runto_main] then {
    perror "couldn't run to breakpoint"
    continue
}

get_debug_format

#go -until 1209
gdb_test "tbreak 1209" \
    "Temporary breakpoint \[0-9\]+.*file.*$srcfile, line 1209.*" \
    "tbreakpoint line 1209"

gdb_test continue \
"Continuing\\..*main \\(\\) at.*$srcfile:1209.*" \
"run until breakpoint set at a line"


#call print_double_array(double_array)
if {![gdb_skip_float_test "print print_double_array(double_array)"] && \
    ![gdb_skip_stdio_test "print print_double_array(double_array)"] } {
    gdb_test_sequence "print print_double_array(double_array)" "" {
	"\[ \t\r\n\]+array_d :"
	"\[ \t\r\n\]+========="
	"\[ \t\r\n\]+0.000000"
	"\[ \t\r\n\]+23.456\[0-9\]*  46.913\[0-9\]*  70.370\[0-9\]*  93.826\[0-9\]*  117.283\[0-9\]*  140.740\[0-9\]*  164.196\[0-9\]*  187.653\[0-9\]"
	"\[ \t\r\n\]+"
    }
}

#call print_char_array(char_array)

if ![gdb_skip_stdio_test "print_char_array(char_array)"] {
    gdb_test_sequence "print print_char_array(char_array)" "" {
	"\[ \t\r\n\]+array_c :"
	"\[ \t\r\n\]+========="
	"\[ \t\r\n\]+\[ \t\r\n\]+Z"
	"\[ \t\r\n\]+aZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZ"
	"\[ \t\r\n\]+aZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZ"
	"\[ \t\r\n\]+aZaZaZaZaZaZaZaZaZa\[ \t\r\n\]+\[ \t\r\n\]+"
    }
}

#go -until 1216
gdb_test "tbreak 1216" \
"Temporary breakpoint.*file.*$srcfile, line 1216.*" \
"tbreakpoint line 1216"

if ![gdb_skip_stdio_test "continue to 1216"] {
    gdb_test_sequence "continue" "continue to 1216" {
	"\[ \t\r\n\]+array_c :"
	"\[ \t\r\n\]+========="
	"\[ \t\r\n\]+\[ \t\r\n\]+Z"
	"\[ \t\r\n\]+aZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZ"
	"\[ \t\r\n\]+aZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZ"
	"\[ \t\r\n\]+aZaZaZaZaZaZaZaZaZa"
	"\[ \t\r\n\]+main.*at.*:1216"
	"\[ \t\r\n\]+1216.*print_double_array\\(double_array\\)"
    }
} else {
    gdb_test "continue" ".*" ""
}

# I am disabling this test, because it takes too long. I verified by
# hand that it works, feel free to check for yourself. 
#call print_all_arrays(integer_array, char_array, float_array, double_array)
#send_gdb "print print_all_arrays(integer_array, char_array, float_array, double_array)\n"
#gdb_expect {
#    -re ".*array_i :\[ \t\r\n\]+=========\[ \t\r\n\]+\[ \t\r\n\]+0\[ \t\r\n\]+-1  -2  -3  -4  -5  -6  -7  -8\[ \t\r\n\]+-9  -10  -11  -12  -13  -14  -15  -16\[ \t\r\n\]+-17  -18  -19  -20  -21  -22  -23  -24\[ \t\r\n\]+-25  -26  -27  -28  -29  -30  -31  -32\[ \t\r\n\]+-33  -34  -35  -36  -37  -38  -39  -40\[ \t\r\n\]+-41  -42  -43  -44  -45  -46  -47  -48\[ \t\r\n\]+-49\[ \t\r\n\]+\[ \t\r\n\]+array_c :\[ \t\r\n\]+=========\[ \t\r\n\]+\[ \t\r\n\]+Z\[ \t\r\n\]+aZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZ\[ \t\r\n\]+aZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZ\[ \t\r\n\]+aZaZaZaZaZaZaZaZaZa\[ \t\r\n\]+\[ \t\r\n\]+array_f :\[ \t\r\n\]+=========\[ \t\r\n\]+\[ \t\r\n\]+0.000000\[ \t\r\n\]+0.142450  0.284900  0.427350  0.569801  0.712251  0.854701  0.997151  1.139601\[ \t\r\n\]+1.282051  1.424501  1.566952  1.709402  1.851852  1.994302\[ \t\r\n\]+\[ \t\r\n\]+array_d :\[ \t\r\n\]+=========\[ \t\r\n\]+\[ \t\r\n\]+0.000000\[ \t\r\n\]+23.456700  46.913400  70.370100  93.826800  117.283500  140.740200  164.196900  187.653600\[ \t\r\n\]+211.110300  234.567000  258.023700  281.480400  304.937100  328.393800  351.850500  375.307200\[ \t\r\n\]+398.763900  422.220600  445.677300  469.134000  492.590700  516.047400  539.504100  562.960800\[ \t\r\n\]+586.41750  609.874200  633.330900  656.787600  680.244300  703.701000  727.157700  750.614400\[ \t\r\n\]+774.071100  797.527800  820.984500  844.441200  867.897900  891.354600  914.811300  938.268000\[ \t\r\n\]+961.724700  985.181400  1008.638100  1032.094800  1055.551500  1079.008200  1102.464900  1125.921600\[ \t\r\n\]+1149.378300  1172.835000  1196.291700  1219.748400  1243.205100  1266.661800  1290.118500  1313.575200\[ \t\r\n\]+1337.031900  1360.488600  1383.945300  1407.402000  1430.858700  1454.315400  1477.772100  1501.228800\[ \t\r\n\]+1524.685500  1548.142200  1571.598900  1595.055600  1618.512300  1641.969000  1665.425700  1688.882400\[ \t\r\n\]+1712.339100  1735.795800  1759.252500  1782.709200  1806.165900  1829.622600  1853.079300  1876.536000\[ \t\r\n\]+1899.992700  1923.449400  1946.906100  1970.362800  1993.819500  2017.276200  2040.732900  2064.189600\[ \t\r\n\]+2087.646300  2111.103000  2134.559700  2158.016400  2181.473100  2204.929800  2228.386500  2251.843200\[ \t\r\n\]+2275.299900  2298.756600  2322.213300.*$gdb_prompt $" {
#        pass "print print_all_arrays(integer_array, char_array, float_array, double_array)"
#   }
#    -re ".*$gdb_prompt $" { fail "print print_all_arrays(integer_array, char_array, float_array, double_array)" }
#    timeout           { fail "(timeout) print print_all_arrays(integer_array, char_array, float_array, double_array)" }
#  }

#set timeout $oldtimeout
#go -until 1220
gdb_test "tbreak 1220" \
	"Temporary breakpoint.* file .*$srcfile, line 1220.*" \
	"tbreakpoint line 1220"

if {![gdb_skip_float_test "continuing to breakpoint 1220"] && \
    ![gdb_skip_stdio_test "continuing to breakpoint 1220"] } {
    gdb_test_sequence "continue" "continuing to breakpoint 1220" {
	"Continuing\\."
	"\[ \t\r\n\]+array_d :"
	"\[ \t\r\n\]+========="
	"\[ \t\r\n\]+0.000000"
	"\[ \t\r\n\]+23.456\[0-9\]*  46.913\[0-9\]*  70.370\[0-9\]*  93.826\[0-9\]*  117.283\[0-9\]*  140.740\[0-9\]*  164.196\[0-9\]*  187.653\[0-9\]*"
	"\[ \t\r\n\]+"
	"array_f :"
	"student id :\[\t \]+.*YELLOW"
	"array_i :"
	"main \\(\\) at .*call-ar-st.c:1220\[ \t\r\n\]+.*print_all_arrays\\(integer_array, char_array, float_array, double_array\\)."
    }
} else {
    gdb_test "continue" ".*" ""
}

#step
gdb_test "step" \
    "print_all_arrays \\(array_i=<integer_array.*>, array_c=<char_array.*> .ZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZaZa., array_f=<float_array.*>, array_d=<double_array.*>\\) at .*call-ar-st.c:306\[ \t\r\n\]+306.*print_int_array\\(array_i\\);.*" \
    "step inside print_all_arrays"

#step -over
if ![gdb_skip_stdio_test "next over print_int_array in print_all_arrays"] {
    gdb_test "next" \
	"array_i :.*307.*print_char_array.*" \
	"next over print_int_array in print-all_arrays"
} else {
    gdb_test "next" ".*" ""
}

#call print_double_array(array_d)
if {![gdb_skip_float_test "print print_double_array(array_d)"] && \
    ![gdb_skip_stdio_test "print print_double_array(array_d)"] } {
    gdb_test_sequence "print print_double_array(array_d)" "" {
	"array_d :"
	"\[ \t\r\n\]+========="
	"\[ \t\r\n\]+\[ \t\r\n\]+0.000000"
	"\[ \t\r\n\]+23.456\[0-9\]*  46.913\[0-9\]*  70.370\[0-9\]*  93.826\[0-9\]*  117.283\[0-9\]*  140.740\[0-9\]*  164.196\[0-9\]*  187.653\[0-9\]*"
	"\[ \t\r\n\]+"
    }
}

#go -until 1236
gdb_test "tbreak 1236" \
"Temporary breakpoint.* file .*$srcfile, line 1236.*" \
"tbreakpoint line 1236"

if {![gdb_skip_float_test "continuing to 1236"] && \
    ![gdb_skip_stdio_test "continuing to 1236"] } {
    gdb_test_sequence "continue" "continuing to 1236" {
	"Continuing\\..*array_c"
	"array_f"
	"\[ \t\r\n\]+array_d :"
	"\[ \t\r\n\]+========="
	"\[ \t\r\n\]+0.000000"
	"\[ \t\r\n\]+23.456\[0-9\]*  46.913\[0-9\]*  70.370\[0-9\]*  93.826\[0-9\]*  117.283\[0-9\]*  140.740\[0-9\]*  164.196\[0-9\]*  187.653\[0-9\]*"
	"\[ \t\r\n\]+.*HELLO WORLD.*main \\(\\) at .*call-ar-st.c:1236.*printf\\(.BYE BYE FOR NOW.n.\\)."
    }
} else {
    gdb_test "continue" ".*" ""
}


#call sum_array_print(10, *list1, *list2, *list3, *list4)

if ![gdb_skip_stdio_test "print sum_array_print(...)"] {
    gdb_test "print sum_array_print(10, *list1, *list2, *list3, *list4)" \
	".*Sum of 4 arrays, by element \\(add in seed as well\\):\[ \t\r\n\]+Seed: 10\[ \t\r\n\]+Element Index . Sum\[ \t\r\n\]+-------------------------\[ \t\r\n\]+.*\[ \t\]+0\[ \t\]+52\[ \t\r\n\]+1\[ \t\]+60\[ \t\r\n\]+2\[ \t\]+68\[ \t\r\n\]+3\[ \t\]+76\[ \t\r\n\]+4\[ \t\]+84\[ \t\r\n\]+5\[ \t\]+92\[ \t\r\n\]+6\[ \t\]+100\[ \t\r\n\]+7\[ \t\]+108\[ \t\r\n\]+8\[ \t\]+116\[ \t\r\n\]+9\[ \t\]+124\[ \t\r\n\]+.*" \
	"print sum_array_print(10, *list1, *list2, *list3, *list4)"
}

#step over
if ![gdb_skip_stdio_test "next to 1237"] {
    gdb_test "next" \
	"BYE BYE FOR NOW.*1237.*printf\\(.VERY GREEN GRASS.n.\\);.*" \
	"next to 1237"
} else {
    gdb_test "next" ".*" ""
}

#call print_array_rep(\*list1, \*list2, \*list3)

if ![gdb_skip_stdio_test "print print_array_rep(...)"] {
    gdb_test "print print_array_rep(\*list1, \*list2, \*list3)" \
	"Contents of linked list3:.*" \
	"print print_array_rep(*list1, *list2, *list3)"
}

#go -until 1241
gdb_test "tbreak 1241" \
    "Temporary breakpoint..* file .*$srcfile, line 1241.*" \
    "tbreakpoint line 1241"

gdb_test "continue" \
    "main \\(\\) at .*call-ar-st.c:1241\r\n1241\[\t \]+sum_array_print\\(10, \\*list1, \\*list2, \\*list3, \\*list4\\);.*" \
    "continue to 1241"


# Run into sum_array_print, and verify that the arguments were passed
# accurately.
#
# Note that we shouldn't use a `step' here to get into
# sum_array_print; GCC may emit calls to memcpy to put the arguments
# in the right place, and a step may end up in memcpy instead.  This
# may itself be a bug, but it's not the one we're trying to catch
# here.  I've added something to step-test.exp for this.
gdb_test "break sum_array_print" \
	".*Breakpoint ${decimal}: file .*call-ar-st.c, line.*" \
	"set breakpoint in sum_array_print"
gdb_test_no_output "set print frame-arguments all"
gdb_test "continue" \
	".*Breakpoint ${decimal}, sum_array_print \\(seed=10, linked_list1=.next_index = .1, 2, 3, 4, 5, 6, 7, 8, 9, 10., values = .4, 6, 8, 10, 12, 14, 16, 18, 20, 22., head = 0., linked_list2=.next_index = .1, 2, 3, 4, 5, 6, 7, 8, 9, 10., values = .8, 10, 12, 14, 16, 18, 20, 22, 24, 26., head = 0., linked_list3=.next_index = .1, 2, 3, 4, 5, 6, 7, 8, 9, 10., values = .10, 12, 14, 16, 18, 20, 22, 24, 26, 28., head = 0., linked_list4=.next_index = .1, 2, 3, 4, 5, 6, 7, 8, 9, 10., values = .20, 22, 24, 26, 28, 30, 32, 34, 36, 38., head = 0.\\) at .*call-ar-st.c:1105\[ \t\n\r\]+1105.*printf\\(.Sum of 4 arrays, by element \\(add in seed as well\\).*\\);.*" \
	"check args of sum_array_print"

#call print_array_rep(linked_list1, linked_list2, linked_list3)
# this calls works from gdb without gdb_expect. But it does seem to hang
#from within gdb_expect.
#I comment this out
#send_gdb "print print_array_rep(linked_list1, linked_list2, linked_list3)\n"
#gdb_expect {
#    -re ".*Contents of linked list1:\[ \t\n\r\]+Element Value . Index of Next Element\[ \t\n\r\]+-------------------------------------\[ \t\n\r\]+.*\[ \t\n\r\]+.*4.*1\[ \t\n\r\]+.*6.*2\[ \t\n\r\]+.*8.*3\[ \t\n\r\]+.*10.*4\[ \t\n\r\]+.*12.*5\[ \t\n\r\]+.*14.*6\[ \t\n\r\]+.*16.*7\[ \t\n\r\]+.*18.*8\[ \t\n\r\]+.*20.*9\[ \t\n\r\]+.*22.*10\[ \t\n\r\]+Contents of linked list2:\[ \t\n\r\]+Element Value | Index of Next Element\[ \t\n\r\]+-------------------------------------\[ \t\n\r\]+.*\[ \t\n\r\]+.*8.*1\[ \t\n\r\]+.*10.*2\[ \t\n\r\]+.*12.*3\[ \t\n\r\]+.*14.*4\[ \t\n\r\]+.*16.*5\[ \t\n\r\]+.*18.*6\[ \t\n\r\]+.*20.*7\[ \t\n\r\]+.*22.*8\[ \t\n\r\]+.*24.*9\[ \t\n\r\]+.*26.*10\[ \t\n\r\]+Contents of linked list3:\[ \t\n\r\]+Element Value | Index of Next Element\[ \t\n\r\]+-------------------------------------\[ \t\n\r\]+.*\[ \t\n\r\]+.*10.*1\[ \t\n\r\]+.*12.*2\[ \t\n\r\]+.*14.*3\[ \t\n\r\]+.*16.*4\[ \t\n\r\]+.*18.*5\[ \t\n\r\]+.*20.*6\[ \t\n\r\]+.*22.*7\[ \t\n\r\]+.*24.*8\[ \t\n\r\]+.*26.*9\[ \t\n\r\]+.*28.*10\[ \t\n\r\]+.*$gdb_prompt $" {
#        pass "print print_array_rep(linked_list1, linked_list2, linked_list3)"
#      }
#    -re ".*$gdb_prompt $" { fail "print print_array_rep(linked_list1, linked_list2, linked_list3)" }
#    timeout           { fail "(timeout) print print_array_rep(linked_list1, linked_list2, linked_list3)" }
#}


#go -until 1281
gdb_test "tbreak 1281" \
    "Temporary breakpoint.* file .*call-ar-st.c, line 1281.*" \
    "tbreakpoint line 1281"

if ![gdb_skip_stdio_test "continuing to 1281"] {
    gdb_test "continue" \
	"Continuing\\..*Sum of 4 arrays.*Contents of linked list1.*Contents of two_floats_t.*main \\(\\) at .*call-ar-st.c:1281.*c = 0.*" \
	"continue to 1281"
} else {
    gdb_test "continue" ".*" ""
}

#call print_small_structs(*struct1, *struct2, *struct3, *struct4, 
#                         *flags, *flags_combo, *three_char, *five_char, 
#                         *int_char_combo, *d1, *d2, *d3, *f1, *f2, *f3)

if {![gdb_skip_float_test "print print_small_structs(...)"] && \
    ![gdb_skip_stdio_test "print print_small_structs(...)"] } {
    gdb_test_sequence "print print_small_structs(*struct1, *struct2, *struct3, *struct4, *flags, *flags_combo, *three_char, *five_char, *int_char_combo, *d1, *d2, *d3, *f1, *f2, *f3)" "print print_small_structs" {
	"\[\t\r\n \]+alpha"
	"\[\t\r\n \]+gamma"
	"\[\t\r\n \]+epsilon"
	"\[\t\r\n \]+alpha"
	"\[\t\r\n \]+gamma"
	"\[\t\r\n \]+epsilon"
	"\[\t\r\n \]+ch1: y[ \t]*ch2: n"
	"\[\t\r\n \]+Contents of three_char_t:"
	"\[\t\r\n \]+a[ \t]*b[ \t]*c"
	"\[\t\r\n \]+Contents of five_char_t:"
	"\[\t\r\n \]+l[ \t]*m[ \t]*n[ \t]*o[ \t]*p"
	"\[\t\r\n \]+Contents of int_char_combo_t:"
	"\[\t\r\n \]+123[ \t]*z"
	"\[\t\r\n \]+Sum of the 4 struct values and seed :"
	"\[\t\r\n \]+52"
	"\[\t\r\n \]+Contents of struct1:"
	"\[\t\r\n \]+6[ \t]*0"
	"\[\t\r\n \]+Contents of struct2:"
	"\[\t\r\n \]+10[ \t]*0"
	"\[\t\r\n \]+Contents of struct3:"
	"\[\t\r\n \]+12[ \t]*0"
	"\[\t\r\n \]+Contents of one_double_t:"
	"\[\t\r\n \]+10.500000"
	"\[\t\r\n \]+Contents of one_double_t:"
	"\[\t\r\n \]+-3.375000"
	"\[\t\r\n \]+Contents of one_double_t:"
	"\[\t\r\n \]+675.093750"
	"\[\t\r\n \]+Contents of two_floats_t:"
	"\[\t\r\n \]+45.234001[ \t]*43.599998"
	"\[\t\r\n \]+Contents of two_floats_t:"
	"\[\t\r\n \]+78.010002[ \t]*122.099998"
	"\[\t\r\n \]+Contents of two_floats_t:"
	"\[\t\r\n \]+-1232.344971[ \t]*-199.210007"
    }
}

#call compute_with_small_structs(20)
gdb_test "print compute_with_small_structs(20)" \
    "\[0-9\]+ = void" \
    "print compute_with_small_structs(20)"


#call print_ten_doubles(123.456, 123.456, -0.12, -1.23, 343434.8, 89.098, 
#                       3.14, -5678.12345, -0.11111111, 216.97065)

if {![gdb_skip_float_test "print print_ten_doubles(...)"] && \
    ![gdb_skip_stdio_test "print print_ten_doubles(...)"]} {
    gdb_test_sequence "print print_ten_doubles(123.456, 123.456, -0.12, -1.23, 343434.8, 89.098, 3.14, -5678.12345, -0.11111111, 216.97065)" "print print_ten_doubles" {
	"\[\t\r\n \]+Two Doubles : 123.45\[0-9\]*.*123.45\[0-9\]*"
	"\[\t\r\n \]+Two Doubles : -0.1200\[0-9\]*.*-1.2300\[0-9\]*"
	"\[\t\r\n \]+Two Doubles : 343434.\[0-9\]*.*89.09\[0-9\]*"
	"\[\t\r\n \]+Two Doubles : 3.1400\[0-9\]*.*-5678.123\[0-9\]*"
	"\[\t\r\n \]+Two Doubles : -0.1111\[0-9\]*.*216.97\[0-9\]*"
    }
}

#go -until 1286
gdb_test "tbreak 1286" \
    "Temporary breakpoint .* file .*call-ar-st.c, line 1286.*" \
    "tbreakpoint line 1286"

gdb_test continue "Continuing\\..*main \\(.*\\) at.*call-ar-st.c:1286\[\t\r\n \]+1286.*print_long_arg_list \\( a, b, c, d, e, f, .struct1, .struct2, .struct3, .struct4,.*" "continue to 1286"

if { [istarget "hppa*-*-hpux*"] } {
    #
    # NOTE:(FIXME)
    # the aCC demangler cannot demangle the name of a function with >10 args.
    # so I added a .* after the name of the function, to match the
    # incredibly long mangled name 
    # (getting aCC's libdemangle.a bundled w/ the system?)
    # DTS CLLbs16994  coulter 990114
    # 
    # FIXME: use step for hppa* testing for now
    # guo 990621
    #
    gdb_test "step" \
	"print_long_arg_list.*\\(a=22.25, b=33.375, c=0, d=-25, e=100, f=2345, struct1=\{value = 6, head = 0\}, struct2=\{value = 10, head = 0\}, struct3=\{value = 12, head = 0\}, struct4=\{value = 14, head = 0\}, flags=\{alpha = 1, beta = 0, gamma = 1, delta = 0, epsilon = 1, omega = 0\}, flags_combo=\{alpha = 1, beta = 0, ch1 = 121 \'y\', gamma = 1, delta = 0, ch2 = 110 \'n\', epsilon = 1, omega = 0\}, three_char=\{ch1 = 97 \'a\', ch2 = 98 \'b\', ch3 = 99 \'c\'\}, five_char=\{ch1 = 108 \'l\', ch2 = 109 \'m\', ch3 = 110 \'n\', ch4 = 111 \'o\', ch5 = 112 \'p\'\}, int_char_combo=\{int1 = 123, ch1 = 122 \'z\'\}, d1=\{double1 = 10.5\}, d2=\{double1 = -3.375\}, d3=\{double1 = 675.09375\}, f1=\{float1 = 45.2340012, float2 = 43.5999985\}, f2=\{float1 = 78.0100021, float2 = 122.099998\}, f3=\{float1 = -1232.34497, float2 = -199.210007\}\\) at .*${srcfile}:992\[\r\n\]+992\[ \t\]+printf\\(\"double :.*\", a\\);" \
	"step into print_long_arg_list"
} else {

    # We can't just assume that a "step" will get us into
    # print_long_arg_list here,either.
    gdb_test "tbreak print_long_arg_list" \
	"Temporary breakpoint .* file .*call-ar-st.c, line .*" \
	"tbreak in print_long_arg_list after stepping into memcpy"
    # The short match case below handles cases where a buffer
    # overflows or something, and expect can't deal with the full
    # line.  Perhaps a more elegant solution exists... -sts 1999-08-17
    if {![gdb_skip_float_test "step into print_long_arg_list"]} {
	gdb_test_multiple "continue" "step into print_long_arg_list" {
	    -re ".*print_long_arg_list \\(a=22.25, b=33.375, c=0, d=-25, e=100, f=2345, struct1=\{value = 6, head = 0\}, struct2=\{value = 10, head = 0\}, struct3=\{value = 12, head = 0\}, struct4=\{value = 14, head = 0\}, flags=\{alpha = 1, beta = 0, gamma = 1, delta = 0, epsilon = 1, omega = 0\}, flags_combo=\{alpha = 1, beta = 0, ch1 = 121 \'y\', gamma = 1, delta = 0, ch2 = 110 \'n\', epsilon = 1, omega = 0\}, three_char=\{ch1 = 97 \'a\', ch2 = 98 \'b\', ch3 = 99 \'c\'\}, five_char=\{ch1 = 108 \'l\', ch2 = 109 \'m\', ch3 = 110 \'n\', ch4 = 111 \'o\', ch5 = 112 \'p\'\}, int_char_combo=\{int1 = 123, ch1 = 122 \'z\'\}, d1=\{double1 = 10.5\}, d2=\{double1 = -3.375\}, d3=\{double1 = 675.09375\}, f1=\{float1 = 45.2340012, float2 = 43.5999985\}, f2=\{float1 = 78.0100021, float2 = 122.099998\}, f3=\{float1 = -1232.34497, float2 = -199.210007\}\\) at .*${srcfile}:992\[\r\n\]+992\[ \t\]+printf\\(\"double :.*\", a\\);.*$gdb_prompt $" {
		pass "step into print_long_arg_list"
	    }
	    -re ".*print_long_arg_list.*\\(a=22.25, b=33.375, c=0, d=-25, e=100, f=2345, struct1=\{value = 6, head = 0\}, struct2=\{value = 10, head = 0\}, struct3=\{value = 12, head = 0\}, struct4=\{value = 14, head = 0\}, flags=\{alpha = 1, beta = 0, gamma = 1, delta = 0, epsilon = 1, omega = 0\}, flags_combo=\{alpha = 1, beta = 0, ch1 = 121 \'y\', gamma = 1, delta = 0, ch2 = 110 \'n\', epsilon = 1, omega = 0\}, three_char=\{ch1 = 97 \'a\', ch2 = 98 \'b\', ch3 = 99 \'c\'\}.*\\) at .*${srcfile}:992\[\r\n\]+992\[ \t\]+printf\\(\"double :.*\", a\\);.*$gdb_prompt $" {
		pass "step into print_long_arg_list (short match)"
	    }
	}
    } else {
	# If skipping float tests, don't expect anything in arg list.
	gdb_test "continue" \
	    "print_long_arg_list \\(.*\\).*" \
	    "step into print_long_arg_list"
    }
}

set ws "\[\n\r\t \]+"

#call print_small_structs(struct1, struct2, struct3, struct4, flags, 
#                         flags_combo, three_char, five_char, int_char_combo, 
#                         d1, d2, d3, f1, f2, f3)

if {![gdb_skip_float_test "print_small_structs from print_long_arg_list"] && \
    ![gdb_skip_stdio_test "print_small_structs from print_long_arg_list"] } {

    # On 32-bit SPARC, some of the args are passed by ref, others by
    # value, and GDB gets confused and says "Invalid cast" because it
    # thinks it has to cast the structure into a pointer to structure.
    if { [test_debug_format "stabs"] } then {
	setup_kfail "gdb/1539" "sparc-*-*"
    }

    gdb_test_sequence "print print_small_structs(struct1, struct2, struct3, struct4, flags, flags_combo, three_char, five_char, int_char_combo, d1, d2, d3, f1, f2, f3)" "print print_small_structs from print_long_arg_list" {
	"\[\t\r\n \]+alpha"
	"\[\t\r\n \]+gamma"
	"\[\t\r\n \]+epsilon"
	"\[\t\r\n \]+alpha"
	"\[\t\r\n \]+gamma"
	"\[\t\r\n \]+epsilon"
	"\[\t\r\n \]+ch1: y[ \t]*ch2: n"
	"\[\t\r\n \]+Contents of three_char_t:"
	"\[\t\r\n \]+a\[ \t\]*b\[ \t\]*c"
	"\[\t\r\n \]+Contents of five_char_t:"
	"\[\t\r\n \]+l\[ \t\]*m\[ \t\]*n\[ \t\]*o\[ \t\]*p"
	"\[\t\r\n \]+Contents of int_char_combo_t:"
	"\[\t\r\n \]+123\[ \t\]*z"
	"\[\t\r\n \]+Sum of the 4 struct values and seed :"
	"\[\t\r\n \]+52"
	"\[\t\r\n \]+Contents of struct1:"
	"\[\t\r\n \]+6\[ \t\]*0"
	"\[\t\r\n \]+Contents of struct2:"
	"\[\t\r\n \]+10\[ \t\]*0"
	"\[\t\r\n \]+Contents of struct3:"
	"\[\t\r\n \]+12\[ \t\]*0"
	"\[\t\r\n \]+Contents of one_double_t:"
	"\[\t\r\n \]+10.500000"
	"\[\t\r\n \]+Contents of one_double_t:"
	"\[\t\r\n \]+-3.375000"
	"\[\t\r\n \]+Contents of one_double_t:"
	"\[\t\r\n \]+675.093750"
	"\[\t\r\n \]+Contents of two_floats_t:"
	"\[\t\r\n \]+45.234001\[ \t\]*43.599998"
	"\[\t\r\n \]+Contents of two_floats_t:"
	"\[\t\r\n \]+78.010002\[ \t\]*122.099998"
	"\[\t\r\n \]+Contents of two_floats_t:"
	"\[\t\r\n \]+-1232.344971\[ \t\]*-199.210007"
    }
}


#go -until 1300
gdb_test "tbreak 1300" \
    "Temporary breakpoint.* file .*call-ar-st.c, line 1300.*" \
    "tbreakpoint line 1300"

if ![gdb_skip_stdio_test "continuing to 1300"] {
    gdb_test "continue" "Continuing\\..*Contents of two_floats_t:.*main \\(\\) at.*call-ar-st.c:1300.*1300.*init_bit_flags_combo\\(flags_combo, \\(unsigned\\)1, \\(unsigned\\)0, .y.,.*" \
	    "continue to 1300"
} else {
    gdb_test "continue" ".*" ""
}

#step
gdb_test "step" \
    "init_bit_flags_combo \\(bit_flags_combo=, a=1, b=0, ch1=121 .y., g=1, d=0, ch2=110 .n., e=1, o=0\\) at .*call-ar-st.c:416\[ \t\n\r\]+416.*bit_flags_combo->alpha = a;" \
    "step into init_bit_flags_combo"

#call print_bit_flags_combo(*bit_flags_combo)
if ![gdb_skip_stdio_test "continuing to 1300"] {
    gdb_test "print print_bit_flags_combo(*bit_flags_combo)" \
	"alpha.*gamma.*epsilon.*ch1: y.*ch2: n.*" \
	"print print_bit_flags_combo from init_bit_flags_combo"
}


#go -until 1305
gdb_test "tbreak 1305" \
    "Temporary breakpoint.* file .*call-ar-st.c, line 1305.*" \
    "tbreakpoint line 1305"

gdb_test continue "Continuing\\..*main \\(\\) at .*call-ar-st.c:1305\[\r\n\t \]+1305.*init_int_char_combo\\(int_char_combo, 13, .!.\\);" \
"continue to 1305"

#call print_long_arg_list(a, b, c, d, e, f, *struct1, *struct2, *struct3, *struct4, *flags, *flags_combo, *three_char, *five_char, *int_char_combo, *d1, *d2, *d3, *f1, *f2, *f3)

# FIXME:
# HP aCC demangler currently does not handle hp aCC functions with >10 args
# DTS CLLbs16994  coulter 990114

if {$hp_aCC_compiler} {setup_xfail "hppa*-*-*" CLLbs16994}

if {![gdb_skip_float_test "print print_long_arg_list"] && \
    ![gdb_skip_stdio_test "print print_long_arg_list"] } {
    gdb_test_sequence "print print_long_arg_list(a, b, c, d, e, f, *struct1, *struct2, *struct3, *struct4, *flags, *flags_combo, *three_char, *five_char, *int_char_combo, *d1, *d2, *d3, *f1, *f2, *f3)" "print print_long_arg_list" {
	"\[ \n\r\t\]+double : 22.250000"
	"\[ \n\r\t\]+double : 33.375000"
	"\[ \n\r\t\]+int : 0"
	"\[ \n\r\t\]+int : -25"
	"\[ \n\r\t\]+int : 100"
	"\[ \n\r\t\]+int : 2345"
	"\[ \n\r\t\]+alpha"
	"\[ \n\r\t\]+gamma"
	"\[ \n\r\t\]+epsilon"
	"\[ \n\r\t\]+ch1: y\[ \t\]+ch2: n"
	"\[ \n\r\t\]+Contents of three_char_t:"
	"\[ \n\r\t\]+x\[ \t\]+y\[ \t\]+z"
	"\[ \n\r\t\]+Contents of five_char_t:"
	"\[ \n\r\t\]+h\[ \t\]+e\[ \t\]+l\[ \t\]+l\[ \t\]+o"
	"\[ \n\r\t\]+Contents of int_char_combo_t:"
	"\[ \n\r\t\]+123\[ \t\]+z"
	"\[ \n\r\t\]+Sum of the 4 struct values and seed :"
	"\[ \n\r\t\]+52"
	"\[ \n\r\t\]+Contents of struct1:"
	"\[ \n\r\t\]+6\[ \t\]+0"
	"\[ \n\r\t\]+Contents of struct2:"
	"\[ \n\r\t\]+10\[ \t\]+0"
	"\[ \n\r\t\]+Contents of struct3:"
	"\[ \n\r\t\]+12\[ \t\]+0"
	"\[ \n\r\t\]+Contents of one_double_t:"
	"\[ \n\r\t\]+1.111110"
	"\[ \n\r\t\]+Contents of one_double_t:"
	"\[ \n\r\t\]+-345.340000"
	"\[ \n\r\t\]+Contents of one_double_t:"
	"\[ \n\r\t\]+546464.200000"
	"\[ \n\r\t\]+Contents of two_floats_t:"
	"\[ \n\r\t\]+0.234000\[ \t\]+453.100006"
	"\[ \n\r\t\]+Contents of two_floats_t:"
	"\[ \n\r\t\]+78.345001\[ \t\]+23.090000"
	"\[ \n\r\t\]+Contents of two_floats_t:"
	"\[ \n\r\t\]+-2.345000\[ \t\]+1.000000"
    }
}


#go -until 1311
gdb_test "tbreak 1311" \
    "Temporary breakpoint.* file .*call-ar-st.c, line 1311.*" \
    "tbreakpoint line 1311"

gdb_test continue "Continuing\\..*main \\(\\) at .*call-ar-st.c:1311\[ \t\n\r\]+1311.*compute_with_small_structs\\(35\\);" \
"continue to 1311"


#call sum_struct_print(10, *struct1, *struct2, *struct3, *struct4)
if ![gdb_skip_stdio_test "print sum_struct_print(...)"] {
    gdb_test "print sum_struct_print(10,*struct1,*struct2,*struct3,*struct4)" \
	"Sum of the 4 struct values and seed :\[ \t\n\r\]+218.*" \
	"print sum_struct_print(10, *struct1, *struct2, *struct3, *struct4)"
}


#call print_struct_rep(*struct1, *struct2, *struct3)
if ![gdb_skip_stdio_test "print print_struct_rep(...)"] {
    gdb_test_sequence "print print_struct_rep(*struct1, *struct2, *struct3)" \
	"print print_struct_rep(*struct1, *struct2, *struct3)" {
	"\[ \t\n\r\]+Contents of struct1:"
	"\[ \t\n\r\]+        22         0"
	"\[ \t\n\r\]+Contents of struct2:"
	"\[ \t\n\r\]+        42         0"
	"\[ \t\n\r\]+Contents of struct3:"
	"\[ \t\n\r\]+        62         0"
    }
}

if ![gdb_skip_stdio_test "print print_one_large_struct(...)"] {
    gdb_test "print print_one_large_struct(*list1)" \
	"         4         1.*" \
	"print print_one_large_struct(*list1)"
}

set timeout $oldtimeout
return

pan class="hl opt">} /* FIXME: cagney/2002-05-22: Should only need to allocate space for the raw registers. Unfortunatly some code still accesses the register array directly using the global registers[]. Until that code has been purged, play safe and over allocating the register buffer. Ulgh! */ descr->sizeof_raw_registers = descr->sizeof_cooked_registers; /* Sanity check. Confirm that there is agreement between the regcache and the target's redundant REGISTER_BYTE (new targets should not even be defining it). */ for (i = 0; i < descr->nr_cooked_registers; i++) { if (REGISTER_BYTE_P ()) gdb_assert (descr->register_offset[i] == REGISTER_BYTE (i)); #if 0 gdb_assert (descr->sizeof_register[i] == REGISTER_RAW_SIZE (i)); gdb_assert (descr->sizeof_register[i] == REGISTER_VIRTUAL_SIZE (i)); #endif } /* gdb_assert (descr->sizeof_raw_registers == DEPRECATED_REGISTER_BYTES (i)); */ return descr; } static struct regcache_descr * regcache_descr (struct gdbarch *gdbarch) { return gdbarch_data (gdbarch, regcache_descr_handle); } static void xfree_regcache_descr (struct gdbarch *gdbarch, void *ptr) { struct regcache_descr *descr = ptr; if (descr == NULL) return; xfree (descr->register_offset); xfree (descr->sizeof_register); descr->register_offset = NULL; descr->sizeof_register = NULL; xfree (descr); } /* Utility functions returning useful register attributes stored in the regcache descr. */ struct type * register_type (struct gdbarch *gdbarch, int regnum) { struct regcache_descr *descr = regcache_descr (gdbarch); gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); return descr->register_type[regnum]; } /* Utility functions returning useful register attributes stored in the regcache descr. */ int register_size (struct gdbarch *gdbarch, int regnum) { struct regcache_descr *descr = regcache_descr (gdbarch); int size; gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS)); size = descr->sizeof_register[regnum]; gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */ gdb_assert (size == REGISTER_RAW_SIZE (regnum)); /* OK */ return size; } /* The register cache for storing raw register values. */ struct regcache { struct regcache_descr *descr; /* The register buffers. A read-only register cache can hold the full [0 .. NUM_REGS + NUM_PSEUDO_REGS) while a read/write register cache can only hold [0 .. NUM_REGS). */ char *registers; char *register_valid_p; /* Is this a read-only cache? A read-only cache is used for saving the target's register state (e.g, across an inferior function call or just before forcing a function return). A read-only cache can only be updated via the methods regcache_dup() and regcache_cpy(). The actual contents are determined by the reggroup_save and reggroup_restore methods. */ int readonly_p; }; struct regcache * regcache_xmalloc (struct gdbarch *gdbarch) { struct regcache_descr *descr; struct regcache *regcache; gdb_assert (gdbarch != NULL); descr = regcache_descr (gdbarch); regcache = XMALLOC (struct regcache); regcache->descr = descr; regcache->registers = XCALLOC (descr->sizeof_raw_registers, char); regcache->register_valid_p = XCALLOC (descr->sizeof_raw_register_valid_p, char); regcache->readonly_p = 1; return regcache; } void regcache_xfree (struct regcache *regcache) { if (regcache == NULL) return; xfree (regcache->registers); xfree (regcache->register_valid_p); xfree (regcache); } static void do_regcache_xfree (void *data) { regcache_xfree (data); } struct cleanup * make_cleanup_regcache_xfree (struct regcache *regcache) { return make_cleanup (do_regcache_xfree, regcache); } /* Return a pointer to register REGNUM's buffer cache. */ static char * register_buffer (struct regcache *regcache, int regnum) { return regcache->registers + regcache->descr->register_offset[regnum]; } void regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read, void *src) { struct gdbarch *gdbarch = dst->descr->gdbarch; char buf[MAX_REGISTER_SIZE]; int regnum; /* The DST should be `read-only', if it wasn't then the save would end up trying to write the register values back out to the target. */ gdb_assert (dst->readonly_p); /* Clear the dest. */ memset (dst->registers, 0, dst->descr->sizeof_cooked_registers); memset (dst->register_valid_p, 0, dst->descr->sizeof_cooked_register_valid_p); /* Copy over any registers (identified by their membership in the save_reggroup) and mark them as valid. The full [0 .. NUM_REGS + NUM_PSEUDO_REGS) range is checked since some architectures need to save/restore `cooked' registers that live in memory. */ for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++) { if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup)) { int valid = cooked_read (src, regnum, buf); if (valid) { memcpy (register_buffer (dst, regnum), buf, register_size (gdbarch, regnum)); dst->register_valid_p[regnum] = 1; } } } } void regcache_restore (struct regcache *dst, regcache_cooked_read_ftype *cooked_read, void *src) { struct gdbarch *gdbarch = dst->descr->gdbarch; char buf[MAX_REGISTER_SIZE]; int regnum; /* The dst had better not be read-only. If it is, the `restore' doesn't make much sense. */ gdb_assert (!dst->readonly_p); /* Copy over any registers, being careful to only restore those that were both saved and need to be restored. The full [0 .. NUM_REGS + NUM_PSEUDO_REGS) range is checked since some architectures need to save/restore `cooked' registers that live in memory. */ for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++) { if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup)) { int valid = cooked_read (src, regnum, buf); if (valid) regcache_cooked_write (dst, regnum, buf); } } } static int do_cooked_read (void *src, int regnum, void *buf) { struct regcache *regcache = src; if (!regcache_valid_p (regcache, regnum) && regcache->readonly_p) /* Don't even think about fetching a register from a read-only cache when the register isn't yet valid. There isn't a target from which the register value can be fetched. */ return 0; regcache_cooked_read (regcache, regnum, buf); return 1; } void regcache_cpy (struct regcache *dst, struct regcache *src) { int i; char *buf; gdb_assert (src != NULL && dst != NULL); gdb_assert (src->descr->gdbarch == dst->descr->gdbarch); gdb_assert (src != dst); gdb_assert (src->readonly_p || dst->readonly_p); if (!src->readonly_p) regcache_save (dst, do_cooked_read, src); else if (!dst->readonly_p) regcache_restore (dst, do_cooked_read, src); else regcache_cpy_no_passthrough (dst, src); } void regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src) { int i; gdb_assert (src != NULL && dst != NULL); gdb_assert (src->descr->gdbarch == dst->descr->gdbarch); /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough move of data into the current_regcache(). Doing this would be silly - it would mean that valid_p would be completly invalid. */ gdb_assert (dst != current_regcache); memcpy (dst->registers, src->registers, dst->descr->sizeof_raw_registers); memcpy (dst->register_valid_p, src->register_valid_p, dst->descr->sizeof_raw_register_valid_p); } struct regcache * regcache_dup (struct regcache *src) { struct regcache *newbuf; gdb_assert (current_regcache != NULL); newbuf = regcache_xmalloc (src->descr->gdbarch); regcache_cpy (newbuf, src); return newbuf; } struct regcache * regcache_dup_no_passthrough (struct regcache *src) { struct regcache *newbuf; gdb_assert (current_regcache != NULL); newbuf = regcache_xmalloc (src->descr->gdbarch); regcache_cpy_no_passthrough (newbuf, src); return newbuf; } int regcache_valid_p (struct regcache *regcache, int regnum) { gdb_assert (regcache != NULL); gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); return regcache->register_valid_p[regnum]; } char * deprecated_grub_regcache_for_registers (struct regcache *regcache) { return regcache->registers; } /* Global structure containing the current regcache. */ /* FIXME: cagney/2002-05-11: The two global arrays registers[] and deprecated_register_valid[] currently point into this structure. */ struct regcache *current_regcache; /* NOTE: this is a write-through cache. There is no "dirty" bit for recording if the register values have been changed (eg. by the user). Therefore all registers must be written back to the target when appropriate. */ /* REGISTERS contains the cached register values (in target byte order). */ char *deprecated_registers; /* DEPRECATED_REGISTER_VALID is 0 if the register needs to be fetched, 1 if it has been fetched, and -1 if the register value was not available. "Not available" indicates that the target is not not able to supply the register at this state. The register may become available at a later time (after the next resume). This often occures when GDB is manipulating a target that contains only a snapshot of the entire system being debugged - some of the registers in such a system may not have been saved. */ signed char *deprecated_register_valid; /* The thread/process associated with the current set of registers. */ static ptid_t registers_ptid; /* * FUNCTIONS: */ /* REGISTER_CACHED() Returns 0 if the value is not in the cache (needs fetch). >0 if the value is in the cache. <0 if the value is permanently unavailable (don't ask again). */ int register_cached (int regnum) { return deprecated_register_valid[regnum]; } /* Record that REGNUM's value is cached if STATE is >0, uncached but fetchable if STATE is 0, and uncached and unfetchable if STATE is <0. */ void set_register_cached (int regnum, int state) { gdb_assert (regnum >= 0); gdb_assert (regnum < current_regcache->descr->nr_raw_registers); current_regcache->register_valid_p[regnum] = state; } /* Return whether register REGNUM is a real register. */ static int real_register (int regnum) { return regnum >= 0 && regnum < NUM_REGS; } /* Low level examining and depositing of registers. The caller is responsible for making sure that the inferior is stopped before calling the fetching routines, or it will get garbage. (a change from GDB version 3, in which the caller got the value from the last stop). */ /* REGISTERS_CHANGED () Indicate that registers may have changed, so invalidate the cache. */ void registers_changed (void) { int i; registers_ptid = pid_to_ptid (-1); /* Force cleanup of any alloca areas if using C alloca instead of a builtin alloca. This particular call is used to clean up areas allocated by low level target code which may build up during lengthy interactions between gdb and the target before gdb gives control to the user (ie watchpoints). */ alloca (0); for (i = 0; i < current_regcache->descr->nr_raw_registers; i++) set_register_cached (i, 0); if (registers_changed_hook) registers_changed_hook (); } /* DEPRECATED_REGISTERS_FETCHED () Indicate that all registers have been fetched, so mark them all valid. */ /* NOTE: cagney/2001-12-04: This function does not set valid on the pseudo-register range since pseudo registers are always supplied using supply_register(). */ /* FIXME: cagney/2001-12-04: This function is DEPRECATED. The target code was blatting the registers[] array and then calling this. Since targets should only be using supply_register() the need for this function/hack is eliminated. */ void deprecated_registers_fetched (void) { int i; for (i = 0; i < NUM_REGS; i++) set_register_cached (i, 1); /* Do not assume that the pseudo-regs have also been fetched. Fetching all real regs NEVER accounts for pseudo-regs. */ } /* deprecated_read_register_bytes and deprecated_write_register_bytes are generally a *BAD* idea. They are inefficient because they need to check for partial updates, which can only be done by scanning through all of the registers and seeing if the bytes that are being read/written fall inside of an invalid register. [The main reason this is necessary is that register sizes can vary, so a simple index won't suffice.] It is far better to call read_register_gen and write_register_gen if you want to get at the raw register contents, as it only takes a regnum as an argument, and therefore can't do a partial register update. Prior to the recent fixes to check for partial updates, both read and deprecated_write_register_bytes always checked to see if any registers were stale, and then called target_fetch_registers (-1) to update the whole set. This caused really slowed things down for remote targets. */ /* Copy INLEN bytes of consecutive data from registers starting with the INREGBYTE'th byte of register data into memory at MYADDR. */ void deprecated_read_register_bytes (int in_start, char *in_buf, int in_len) { int in_end = in_start + in_len; int regnum; char reg_buf[MAX_REGISTER_SIZE]; /* See if we are trying to read bytes from out-of-date registers. If so, update just those registers. */ for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) { int reg_start; int reg_end; int reg_len; int start; int end; int byte; reg_start = REGISTER_BYTE (regnum); reg_len = REGISTER_RAW_SIZE (regnum); reg_end = reg_start + reg_len; if (reg_end <= in_start || in_end <= reg_start) /* The range the user wants to read doesn't overlap with regnum. */ continue; if (REGISTER_NAME (regnum) != NULL && *REGISTER_NAME (regnum) != '\0') /* Force the cache to fetch the entire register. */ deprecated_read_register_gen (regnum, reg_buf); else /* Legacy note: even though this register is ``invalid'' we still need to return something. It would appear that some code relies on apparent gaps in the register array also being returned. */ /* FIXME: cagney/2001-08-18: This is just silly. It defeats the entire register read/write flow of control. Must resist temptation to return 0xdeadbeef. */ memcpy (reg_buf, &deprecated_registers[reg_start], reg_len); /* Legacy note: This function, for some reason, allows a NULL input buffer. If the buffer is NULL, the registers are still fetched, just the final transfer is skipped. */ if (in_buf == NULL) continue; /* start = max (reg_start, in_start) */ if (reg_start > in_start) start = reg_start; else start = in_start; /* end = min (reg_end, in_end) */ if (reg_end < in_end) end = reg_end; else end = in_end; /* Transfer just the bytes common to both IN_BUF and REG_BUF */ for (byte = start; byte < end; byte++) { in_buf[byte - in_start] = reg_buf[byte - reg_start]; } } } /* Read register REGNUM into memory at MYADDR, which must be large enough for REGISTER_RAW_BYTES (REGNUM). Target byte-order. If the register is known to be the size of a CORE_ADDR or smaller, read_register can be used instead. */ static void legacy_read_register_gen (int regnum, char *myaddr) { gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS)); if (! ptid_equal (registers_ptid, inferior_ptid)) { registers_changed (); registers_ptid = inferior_ptid; } if (!register_cached (regnum)) target_fetch_registers (regnum); memcpy (myaddr, register_buffer (current_regcache, regnum), REGISTER_RAW_SIZE (regnum)); } void regcache_raw_read (struct regcache *regcache, int regnum, void *buf) { gdb_assert (regcache != NULL && buf != NULL); gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); if (regcache->descr->legacy_p && !regcache->readonly_p) { gdb_assert (regcache == current_regcache); /* For moment, just use underlying legacy code. Ulgh!!! This silently and very indirectly updates the regcache's regcache via the global deprecated_register_valid[]. */ legacy_read_register_gen (regnum, buf); return; } /* Make certain that the register cache is up-to-date with respect to the current thread. This switching shouldn't be necessary only there is still only one target side register cache. Sigh! On the bright side, at least there is a regcache object. */ if (!regcache->readonly_p) { gdb_assert (regcache == current_regcache); if (! ptid_equal (registers_ptid, inferior_ptid)) { registers_changed (); registers_ptid = inferior_ptid; } if (!register_cached (regnum)) target_fetch_registers (regnum); } /* Copy the value directly into the register cache. */ memcpy (buf, register_buffer (regcache, regnum), regcache->descr->sizeof_register[regnum]); } void regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val) { char *buf; gdb_assert (regcache != NULL); gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); buf = alloca (regcache->descr->sizeof_register[regnum]); regcache_raw_read (regcache, regnum, buf); (*val) = extract_signed_integer (buf, regcache->descr->sizeof_register[regnum]); } void regcache_raw_read_unsigned (struct regcache *regcache, int regnum, ULONGEST *val) { char *buf; gdb_assert (regcache != NULL); gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); buf = alloca (regcache->descr->sizeof_register[regnum]); regcache_raw_read (regcache, regnum, buf); (*val) = extract_unsigned_integer (buf, regcache->descr->sizeof_register[regnum]); } void regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val) { void *buf; gdb_assert (regcache != NULL); gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers); buf = alloca (regcache->descr->sizeof_register[regnum]); store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val); regcache_raw_write (regcache, regnum, buf); } void regcache_raw_write_unsigned (struct regcache *regcache, int regnum, ULONGEST val) { void *buf; gdb_assert (regcache != NULL); gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers); buf = alloca (regcache->descr->sizeof_register[regnum]); store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val); regcache_raw_write (regcache, regnum, buf); } void deprecated_read_register_gen (int regnum, char *buf) { gdb_assert (current_regcache != NULL); gdb_assert (current_regcache->descr->gdbarch == current_gdbarch); if (current_regcache->descr->legacy_p) { legacy_read_register_gen (regnum, buf); return; } regcache_cooked_read (current_regcache, regnum, buf); } void regcache_cooked_read (struct regcache *regcache, int regnum, void *buf) { gdb_assert (regnum >= 0); gdb_assert (regnum < regcache->descr->nr_cooked_registers); if (regnum < regcache->descr->nr_raw_registers) regcache_raw_read (regcache, regnum, buf); else if (regcache->readonly_p && regnum < regcache->descr->nr_cooked_registers && regcache->register_valid_p[regnum]) /* Read-only register cache, perhaphs the cooked value was cached? */ memcpy (buf, register_buffer (regcache, regnum), regcache->descr->sizeof_register[regnum]); else gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache, regnum, buf); } void regcache_cooked_read_signed (struct regcache *regcache, int regnum, LONGEST *val) { char *buf; gdb_assert (regcache != NULL); gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers); buf = alloca (regcache->descr->sizeof_register[regnum]); regcache_cooked_read (regcache, regnum, buf); (*val) = extract_signed_integer (buf, regcache->descr->sizeof_register[regnum]); } void regcache_cooked_read_unsigned (struct regcache *regcache, int regnum, ULONGEST *val) { char *buf; gdb_assert (regcache != NULL); gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers); buf = alloca (regcache->descr->sizeof_register[regnum]); regcache_cooked_read (regcache, regnum, buf); (*val) = extract_unsigned_integer (buf, regcache->descr->sizeof_register[regnum]); } void regcache_cooked_write_signed (struct regcache *regcache, int regnum, LONGEST val) { void *buf; gdb_assert (regcache != NULL); gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers); buf = alloca (regcache->descr->sizeof_register[regnum]); store_signed_integer (buf, regcache->descr->sizeof_register[regnum], val); regcache_cooked_write (regcache, regnum, buf); } void regcache_cooked_write_unsigned (struct regcache *regcache, int regnum, ULONGEST val) { void *buf; gdb_assert (regcache != NULL); gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers); buf = alloca (regcache->descr->sizeof_register[regnum]); store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], val); regcache_cooked_write (regcache, regnum, buf); } /* Write register REGNUM at MYADDR to the target. MYADDR points at REGISTER_RAW_BYTES(REGNUM), which must be in target byte-order. */ static void legacy_write_register_gen (int regnum, const void *myaddr) { int size; gdb_assert (regnum >= 0 && regnum < (NUM_REGS + NUM_PSEUDO_REGS)); /* On the sparc, writing %g0 is a no-op, so we don't even want to change the registers array if something writes to this register. */ if (CANNOT_STORE_REGISTER (regnum)) return; if (! ptid_equal (registers_ptid, inferior_ptid)) { registers_changed (); registers_ptid = inferior_ptid; } size = REGISTER_RAW_SIZE (regnum); if (real_register (regnum)) { /* If we have a valid copy of the register, and new value == old value, then don't bother doing the actual store. */ if (register_cached (regnum) && (memcmp (register_buffer (current_regcache, regnum), myaddr, size) == 0)) return; else target_prepare_to_store (); } memcpy (register_buffer (current_regcache, regnum), myaddr, size); set_register_cached (regnum, 1); target_store_registers (regnum); } void regcache_raw_write (struct regcache *regcache, int regnum, const void *buf) { gdb_assert (regcache != NULL && buf != NULL); gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); gdb_assert (!regcache->readonly_p); if (regcache->descr->legacy_p) { /* For moment, just use underlying legacy code. Ulgh!!! This silently and very indirectly updates the regcache's buffers via the globals deprecated_register_valid[] and registers[]. */ gdb_assert (regcache == current_regcache); legacy_write_register_gen (regnum, buf); return; } /* On the sparc, writing %g0 is a no-op, so we don't even want to change the registers array if something writes to this register. */ if (CANNOT_STORE_REGISTER (regnum)) return; /* Make certain that the correct cache is selected. */ gdb_assert (regcache == current_regcache); if (! ptid_equal (registers_ptid, inferior_ptid)) { registers_changed (); registers_ptid = inferior_ptid; } /* If we have a valid copy of the register, and new value == old value, then don't bother doing the actual store. */ if (regcache_valid_p (regcache, regnum) && (memcmp (register_buffer (regcache, regnum), buf, regcache->descr->sizeof_register[regnum]) == 0)) return; target_prepare_to_store (); memcpy (register_buffer (regcache, regnum), buf, regcache->descr->sizeof_register[regnum]); regcache->register_valid_p[regnum] = 1; target_store_registers (regnum); } void deprecated_write_register_gen (int regnum, char *buf) { gdb_assert (current_regcache != NULL); gdb_assert (current_regcache->descr->gdbarch == current_gdbarch); if (current_regcache->descr->legacy_p) { legacy_write_register_gen (regnum, buf); return; } regcache_cooked_write (current_regcache, regnum, buf); } void regcache_cooked_write (struct regcache *regcache, int regnum, const void *buf) { gdb_assert (regnum >= 0); gdb_assert (regnum < regcache->descr->nr_cooked_registers); if (regnum < regcache->descr->nr_raw_registers) regcache_raw_write (regcache, regnum, buf); else gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache, regnum, buf); } /* Copy INLEN bytes of consecutive data from memory at MYADDR into registers starting with the MYREGSTART'th byte of register data. */ void deprecated_write_register_bytes (int myregstart, char *myaddr, int inlen) { int myregend = myregstart + inlen; int regnum; target_prepare_to_store (); /* Scan through the registers updating any that are covered by the range myregstart<=>myregend using write_register_gen, which does nice things like handling threads, and avoiding updates when the new and old contents are the same. */ for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++) { int regstart, regend; regstart = REGISTER_BYTE (regnum); regend = regstart + REGISTER_RAW_SIZE (regnum); /* Is this register completely outside the range the user is writing? */ if (myregend <= regstart || regend <= myregstart) /* do nothing */ ; /* Is this register completely within the range the user is writing? */ else if (myregstart <= regstart && regend <= myregend) deprecated_write_register_gen (regnum, myaddr + (regstart - myregstart)); /* The register partially overlaps the range being written. */ else { char regbuf[MAX_REGISTER_SIZE]; /* What's the overlap between this register's bytes and those the caller wants to write? */ int overlapstart = max (regstart, myregstart); int overlapend = min (regend, myregend); /* We may be doing a partial update of an invalid register. Update it from the target before scribbling on it. */ deprecated_read_register_gen (regnum, regbuf); memcpy (&deprecated_registers[overlapstart], myaddr + (overlapstart - myregstart), overlapend - overlapstart); target_store_registers (regnum); } } } /* Perform a partial register transfer using a read, modify, write operation. */ typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum, void *buf); typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum, const void *buf); static void regcache_xfer_part (struct regcache *regcache, int regnum, int offset, int len, void *in, const void *out, regcache_read_ftype *read, regcache_write_ftype *write) { struct regcache_descr *descr = regcache->descr; bfd_byte reg[MAX_REGISTER_SIZE]; gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]); gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]); /* Something to do? */ if (offset + len == 0) return; /* Read (when needed) ... */ if (in != NULL || offset > 0 || offset + len < descr->sizeof_register[regnum]) { gdb_assert (read != NULL); read (regcache, regnum, reg); } /* ... modify ... */ if (in != NULL) memcpy (in, reg + offset, len); if (out != NULL) memcpy (reg + offset, out, len); /* ... write (when needed). */ if (out != NULL) { gdb_assert (write != NULL); write (regcache, regnum, reg); } } void regcache_raw_read_part (struct regcache *regcache, int regnum, int offset, int len, void *buf) { struct regcache_descr *descr = regcache->descr; gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers); regcache_xfer_part (regcache, regnum, offset, len, buf, NULL, regcache_raw_read, regcache_raw_write); } void regcache_raw_write_part (struct regcache *regcache, int regnum, int offset, int len, const void *buf) { struct regcache_descr *descr = regcache->descr; gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers); regcache_xfer_part (regcache, regnum, offset, len, NULL, buf, regcache_raw_read, regcache_raw_write); } void regcache_cooked_read_part (struct regcache *regcache, int regnum, int offset, int len, void *buf) { struct regcache_descr *descr = regcache->descr; gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); regcache_xfer_part (regcache, regnum, offset, len, buf, NULL, regcache_cooked_read, regcache_cooked_write); } void regcache_cooked_write_part (struct regcache *regcache, int regnum, int offset, int len, const void *buf) { struct regcache_descr *descr = regcache->descr; gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); regcache_xfer_part (regcache, regnum, offset, len, NULL, buf, regcache_cooked_read, regcache_cooked_write); } /* Hack to keep code that view the register buffer as raw bytes working. */ int register_offset_hack (struct gdbarch *gdbarch, int regnum) { struct regcache_descr *descr = regcache_descr (gdbarch); gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); return descr->register_offset[regnum]; } /* Return the contents of register REGNUM as an unsigned integer. */ ULONGEST read_register (int regnum) { char *buf = alloca (REGISTER_RAW_SIZE (regnum)); deprecated_read_register_gen (regnum, buf); return (extract_unsigned_integer (buf, REGISTER_RAW_SIZE (regnum))); } ULONGEST read_register_pid (int regnum, ptid_t ptid) { ptid_t save_ptid; int save_pid; CORE_ADDR retval; if (ptid_equal (ptid, inferior_ptid)) return read_register (regnum); save_ptid = inferior_ptid; inferior_ptid = ptid; retval = read_register (regnum); inferior_ptid = save_ptid; return retval; } /* Store VALUE into the raw contents of register number REGNUM. */ void write_register (int regnum, LONGEST val) { void *buf; int size; size = REGISTER_RAW_SIZE (regnum); buf = alloca (size); store_signed_integer (buf, size, (LONGEST) val); deprecated_write_register_gen (regnum, buf); } void write_register_pid (int regnum, CORE_ADDR val, ptid_t ptid) { ptid_t save_ptid; if (ptid_equal (ptid, inferior_ptid)) { write_register (regnum, val); return; } save_ptid = inferior_ptid; inferior_ptid = ptid; write_register (regnum, val); inferior_ptid = save_ptid; } /* SUPPLY_REGISTER() Record that register REGNUM contains VAL. This is used when the value is obtained from the inferior or core dump, so there is no need to store the value there. If VAL is a NULL pointer, then it's probably an unsupported register. We just set its value to all zeros. We might want to record this fact, and report it to the users of read_register and friends. */ void supply_register (int regnum, const void *val) { #if 1 if (! ptid_equal (registers_ptid, inferior_ptid)) { registers_changed (); registers_ptid = inferior_ptid; } #endif set_register_cached (regnum, 1); if (val) memcpy (register_buffer (current_regcache, regnum), val, REGISTER_RAW_SIZE (regnum)); else memset (register_buffer (current_regcache, regnum), '\000', REGISTER_RAW_SIZE (regnum)); /* On some architectures, e.g. HPPA, there are a few stray bits in some registers, that the rest of the code would like to ignore. */ /* NOTE: cagney/2001-03-16: The macro CLEAN_UP_REGISTER_VALUE is going to be deprecated. Instead architectures will leave the raw register value as is and instead clean things up as they pass through the method gdbarch_pseudo_register_read() clean up the values. */ #ifdef DEPRECATED_CLEAN_UP_REGISTER_VALUE DEPRECATED_CLEAN_UP_REGISTER_VALUE \ (regnum, register_buffer (current_regcache, regnum)); #endif } void regcache_collect (int regnum, void *buf) { memcpy (buf, register_buffer (current_regcache, regnum), REGISTER_RAW_SIZE (regnum)); } /* read_pc, write_pc, read_sp, deprecated_read_fp, etc. Special handling for registers PC, SP, and FP. */ /* NOTE: cagney/2001-02-18: The functions read_pc_pid(), read_pc(), read_sp(), and deprecated_read_fp(), will eventually be replaced by per-frame methods. Instead of relying on the global INFERIOR_PTID, they will use the contextual information provided by the FRAME. These functions do not belong in the register cache. */ /* NOTE: cagney/2003-06-07: The functions generic_target_write_pc(), write_pc_pid(), write_pc(), and deprecated_read_fp(), all need to be replaced by something that does not rely on global state. But what? */ CORE_ADDR read_pc_pid (ptid_t ptid) { ptid_t saved_inferior_ptid; CORE_ADDR pc_val; /* In case ptid != inferior_ptid. */ saved_inferior_ptid = inferior_ptid; inferior_ptid = ptid; if (TARGET_READ_PC_P ()) pc_val = TARGET_READ_PC (ptid); /* Else use per-frame method on get_current_frame. */ else if (PC_REGNUM >= 0) { CORE_ADDR raw_val = read_register_pid (PC_REGNUM, ptid); CORE_ADDR pc_val = ADDR_BITS_REMOVE (raw_val); return pc_val; } else internal_error (__FILE__, __LINE__, "read_pc_pid: Unable to find PC"); inferior_ptid = saved_inferior_ptid; return pc_val; } CORE_ADDR read_pc (void) { return read_pc_pid (inferior_ptid); } void generic_target_write_pc (CORE_ADDR pc, ptid_t ptid) { #ifdef PC_REGNUM if (PC_REGNUM >= 0) write_register_pid (PC_REGNUM, pc, ptid); if (NPC_REGNUM >= 0) write_register_pid (NPC_REGNUM, pc + 4, ptid); #else internal_error (__FILE__, __LINE__, "generic_target_write_pc"); #endif } void write_pc_pid (CORE_ADDR pc, ptid_t ptid) { ptid_t saved_inferior_ptid; /* In case ptid != inferior_ptid. */ saved_inferior_ptid = inferior_ptid; inferior_ptid = ptid; TARGET_WRITE_PC (pc, ptid); inferior_ptid = saved_inferior_ptid; } void write_pc (CORE_ADDR pc) { write_pc_pid (pc, inferior_ptid); } /* Cope with strage ways of getting to the stack and frame pointers */ CORE_ADDR read_sp (void) { if (TARGET_READ_SP_P ()) return TARGET_READ_SP (); else if (gdbarch_unwind_sp_p (current_gdbarch)) return get_frame_sp (get_current_frame ()); else if (SP_REGNUM >= 0) /* Try SP_REGNUM last: this makes all sorts of [wrong] assumptions about the architecture so put it at the end. */ return read_register (SP_REGNUM); internal_error (__FILE__, __LINE__, "read_sp: Unable to find SP"); } void deprecated_write_sp (CORE_ADDR val) { gdb_assert (SP_REGNUM >= 0); write_register (SP_REGNUM, val); } CORE_ADDR deprecated_read_fp (void) { if (DEPRECATED_TARGET_READ_FP_P ()) return DEPRECATED_TARGET_READ_FP (); else if (DEPRECATED_FP_REGNUM >= 0) return read_register (DEPRECATED_FP_REGNUM); else internal_error (__FILE__, __LINE__, "deprecated_read_fp"); } /* ARGSUSED */ static void reg_flush_command (char *command, int from_tty) { /* Force-flush the register cache. */ registers_changed (); if (from_tty) printf_filtered ("Register cache flushed.\n"); } static void build_regcache (void) { current_regcache = regcache_xmalloc (current_gdbarch); current_regcache->readonly_p = 0; deprecated_registers = deprecated_grub_regcache_for_registers (current_regcache); deprecated_register_valid = current_regcache->register_valid_p; } static void dump_endian_bytes (struct ui_file *file, enum bfd_endian endian, const unsigned char *buf, long len) { int i; switch (endian) { case BFD_ENDIAN_BIG: for (i = 0; i < len; i++) fprintf_unfiltered (file, "%02x", buf[i]); break; case BFD_ENDIAN_LITTLE: for (i = len - 1; i >= 0; i--) fprintf_unfiltered (file, "%02x", buf[i]); break; default: internal_error (__FILE__, __LINE__, "Bad switch"); } } enum regcache_dump_what { regcache_dump_none, regcache_dump_raw, regcache_dump_cooked, regcache_dump_groups }; static void regcache_dump (struct regcache *regcache, struct ui_file *file, enum regcache_dump_what what_to_dump) { struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); struct gdbarch *gdbarch = regcache->descr->gdbarch; struct reggroup *const *groups = reggroups (gdbarch); int regnum; int footnote_nr = 0; int footnote_register_size = 0; int footnote_register_offset = 0; int footnote_register_type_name_null = 0; long register_offset = 0; unsigned char buf[MAX_REGISTER_SIZE]; #if 0 fprintf_unfiltered (file, "legacy_p %d\n", regcache->descr->legacy_p); fprintf_unfiltered (file, "nr_raw_registers %d\n", regcache->descr->nr_raw_registers); fprintf_unfiltered (file, "nr_cooked_registers %d\n", regcache->descr->nr_cooked_registers); fprintf_unfiltered (file, "sizeof_raw_registers %ld\n", regcache->descr->sizeof_raw_registers); fprintf_unfiltered (file, "sizeof_raw_register_valid_p %ld\n", regcache->descr->sizeof_raw_register_valid_p); fprintf_unfiltered (file, "NUM_REGS %d\n", NUM_REGS); fprintf_unfiltered (file, "NUM_PSEUDO_REGS %d\n", NUM_PSEUDO_REGS); #endif gdb_assert (regcache->descr->nr_cooked_registers == (NUM_REGS + NUM_PSEUDO_REGS)); for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++) { /* Name. */ if (regnum < 0) fprintf_unfiltered (file, " %-10s", "Name"); else { const char *p = REGISTER_NAME (regnum); if (p == NULL) p = ""; else if (p[0] == '\0') p = "''"; fprintf_unfiltered (file, " %-10s", p); } /* Number. */ if (regnum < 0) fprintf_unfiltered (file, " %4s", "Nr"); else fprintf_unfiltered (file, " %4d", regnum); /* Relative number. */ if (regnum < 0) fprintf_unfiltered (file, " %4s", "Rel"); else if (regnum < NUM_REGS) fprintf_unfiltered (file, " %4d", regnum); else fprintf_unfiltered (file, " %4d", (regnum - NUM_REGS)); /* Offset. */ if (regnum < 0) fprintf_unfiltered (file, " %6s ", "Offset"); else { fprintf_unfiltered (file, " %6ld", regcache->descr->register_offset[regnum]); if (register_offset != regcache->descr->register_offset[regnum] || register_offset != REGISTER_BYTE (regnum) || (regnum > 0 && (regcache->descr->register_offset[regnum] != (regcache->descr->register_offset[regnum - 1] + regcache->descr->sizeof_register[regnum - 1]))) ) { if (!footnote_register_offset) footnote_register_offset = ++footnote_nr; fprintf_unfiltered (file, "*%d", footnote_register_offset); } else fprintf_unfiltered (file, " "); register_offset = (regcache->descr->register_offset[regnum] + regcache->descr->sizeof_register[regnum]); } /* Size. */ if (regnum < 0) fprintf_unfiltered (file, " %5s ", "Size"); else { fprintf_unfiltered (file, " %5ld", regcache->descr->sizeof_register[regnum]); if ((regcache->descr->sizeof_register[regnum] != REGISTER_RAW_SIZE (regnum)) || (regcache->descr->sizeof_register[regnum] != REGISTER_VIRTUAL_SIZE (regnum)) || (regcache->descr->sizeof_register[regnum] != TYPE_LENGTH (register_type (regcache->descr->gdbarch, regnum))) ) { if (!footnote_register_size) footnote_register_size = ++footnote_nr; fprintf_unfiltered (file, "*%d", footnote_register_size); } else