xref: /netbsd-src/external/gpl3/gdb/dist/opcodes/disassemble.c (revision 6d25fc84cc376538beb81e639c19dc72ed59d740)
1 /* Select disassembly routine for specified architecture.
2    Copyright (C) 1994-2024 Free Software Foundation, Inc.
3 
4    This file is part of the GNU opcodes library.
5 
6    This library is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19    MA 02110-1301, USA.  */
20 
21 #include "sysdep.h"
22 #include "disassemble.h"
23 #include "safe-ctype.h"
24 #include "opintl.h"
25 
26 #ifdef ARCH_all
27 #ifdef BFD64
28 #define ARCH_aarch64
29 #define ARCH_alpha
30 #define ARCH_bpf
31 #define ARCH_ia64
32 #define ARCH_loongarch
33 #define ARCH_mips
34 #define ARCH_mmix
35 #define ARCH_nfp
36 #define ARCH_riscv
37 #define ARCH_score
38 #define ARCH_tilegx
39 #endif
40 #define ARCH_arc
41 #define ARCH_arm
42 #define ARCH_avr
43 #define ARCH_bfin
44 #define ARCH_cr16
45 #define ARCH_cris
46 #define ARCH_crx
47 #define ARCH_csky
48 #define ARCH_d10v
49 #define ARCH_d30v
50 #define ARCH_dlx
51 #define ARCH_epiphany
52 #define ARCH_fr30
53 #define ARCH_frv
54 #define ARCH_ft32
55 #define ARCH_h8300
56 #define ARCH_hppa
57 #define ARCH_i386
58 #define ARCH_ip2k
59 #define ARCH_iq2000
60 #define ARCH_kvx
61 #define ARCH_lm32
62 #define ARCH_m32c
63 #define ARCH_m32r
64 #define ARCH_m68hc11
65 #define ARCH_m68hc12
66 #define ARCH_m68k
67 #define ARCH_mcore
68 #define ARCH_mep
69 #define ARCH_metag
70 #define ARCH_microblaze
71 #define ARCH_mn10200
72 #define ARCH_mn10300
73 #define ARCH_moxie
74 #define ARCH_mt
75 #define ARCH_msp430
76 #define ARCH_nds32
77 #define ARCH_nios2
78 #define ARCH_ns32k
79 #define ARCH_or1k
80 #define ARCH_pdp11
81 #define ARCH_pj
82 #define ARCH_powerpc
83 #define ARCH_pru
84 #define ARCH_rs6000
85 #define ARCH_rl78
86 #define ARCH_rx
87 #define ARCH_s12z
88 #define ARCH_s390
89 #define ARCH_sh
90 #define ARCH_sparc
91 #define ARCH_spu
92 #define ARCH_tic30
93 #define ARCH_tic4x
94 #define ARCH_tic54x
95 #define ARCH_tic6x
96 #define ARCH_tilepro
97 #define ARCH_v850
98 #define ARCH_vax
99 #define ARCH_visium
100 #define ARCH_wasm32
101 #define ARCH_xstormy16
102 #define ARCH_xgate
103 #define ARCH_xtensa
104 #define ARCH_z80
105 #define ARCH_z8k
106 #endif
107 
108 #ifdef ARCH_m32c
109 #include "m32c-desc.h"
110 #endif
111 
112 disassembler_ftype
113 disassembler (enum bfd_architecture a,
114 	      bool big ATTRIBUTE_UNUSED,
115 	      unsigned long mach ATTRIBUTE_UNUSED,
116 	      bfd *abfd ATTRIBUTE_UNUSED)
117 {
118   disassembler_ftype disassemble;
119 
120   switch (a)
121     {
122       /* If you add a case to this table, also add it to the
123 	 ARCH_all definition right above this function.  */
124 #ifdef ARCH_aarch64
125     case bfd_arch_aarch64:
126       disassemble = print_insn_aarch64;
127       break;
128 #endif
129 #ifdef ARCH_alpha
130     case bfd_arch_alpha:
131       disassemble = print_insn_alpha;
132       break;
133 #endif
134 #ifdef ARCH_arc
135     case bfd_arch_arc:
136       disassemble = arc_get_disassembler (abfd);
137       break;
138 #endif
139 #ifdef ARCH_arm
140     case bfd_arch_arm:
141       if (big)
142 	disassemble = print_insn_big_arm;
143       else
144 	disassemble = print_insn_little_arm;
145       break;
146 #endif
147 #ifdef ARCH_avr
148     case bfd_arch_avr:
149       disassemble = print_insn_avr;
150       break;
151 #endif
152 #ifdef ARCH_bfin
153     case bfd_arch_bfin:
154       disassemble = print_insn_bfin;
155       break;
156 #endif
157 #ifdef ARCH_cr16
158     case bfd_arch_cr16:
159       disassemble = print_insn_cr16;
160       break;
161 #endif
162 #ifdef ARCH_cris
163     case bfd_arch_cris:
164       disassemble = cris_get_disassembler (abfd);
165       break;
166 #endif
167 #ifdef ARCH_crx
168     case bfd_arch_crx:
169       disassemble = print_insn_crx;
170       break;
171 #endif
172 #ifdef ARCH_csky
173     case bfd_arch_csky:
174       disassemble = csky_get_disassembler (abfd);
175       break;
176 #endif
177 
178 #ifdef ARCH_d10v
179     case bfd_arch_d10v:
180       disassemble = print_insn_d10v;
181       break;
182 #endif
183 #ifdef ARCH_d30v
184     case bfd_arch_d30v:
185       disassemble = print_insn_d30v;
186       break;
187 #endif
188 #ifdef ARCH_dlx
189     case bfd_arch_dlx:
190       /* As far as I know we only handle big-endian DLX objects.  */
191       disassemble = print_insn_dlx;
192       break;
193 #endif
194 #ifdef ARCH_h8300
195     case bfd_arch_h8300:
196       if (mach == bfd_mach_h8300h || mach == bfd_mach_h8300hn)
197 	disassemble = print_insn_h8300h;
198       else if (mach == bfd_mach_h8300s
199 	       || mach == bfd_mach_h8300sn
200 	       || mach == bfd_mach_h8300sx
201 	       || mach == bfd_mach_h8300sxn)
202 	disassemble = print_insn_h8300s;
203       else
204 	disassemble = print_insn_h8300;
205       break;
206 #endif
207 #ifdef ARCH_hppa
208     case bfd_arch_hppa:
209       disassemble = print_insn_hppa;
210       break;
211 #endif
212 #ifdef ARCH_i386
213     case bfd_arch_i386:
214     case bfd_arch_iamcu:
215       disassemble = print_insn_i386;
216       break;
217 #endif
218 #ifdef ARCH_ia64
219     case bfd_arch_ia64:
220       disassemble = print_insn_ia64;
221       break;
222 #endif
223 #ifdef ARCH_ip2k
224     case bfd_arch_ip2k:
225       disassemble = print_insn_ip2k;
226       break;
227 #endif
228 #ifdef ARCH_bpf
229     case bfd_arch_bpf:
230       disassemble = print_insn_bpf;
231       break;
232 #endif
233 #ifdef ARCH_epiphany
234     case bfd_arch_epiphany:
235       disassemble = print_insn_epiphany;
236       break;
237 #endif
238 #ifdef ARCH_fr30
239     case bfd_arch_fr30:
240       disassemble = print_insn_fr30;
241       break;
242 #endif
243 #ifdef ARCH_kvx
244     case bfd_arch_kvx:
245       disassemble = print_insn_kvx;
246       break;
247 #endif
248 #ifdef ARCH_lm32
249     case bfd_arch_lm32:
250       disassemble = print_insn_lm32;
251       break;
252 #endif
253 #ifdef ARCH_m32r
254     case bfd_arch_m32r:
255       disassemble = print_insn_m32r;
256       break;
257 #endif
258 #if defined(ARCH_m68hc11) || defined(ARCH_m68hc12) \
259     || defined(ARCH_9s12x) || defined(ARCH_m9s12xg)
260     case bfd_arch_m68hc11:
261       disassemble = print_insn_m68hc11;
262       break;
263     case bfd_arch_m68hc12:
264       disassemble = print_insn_m68hc12;
265       break;
266     case bfd_arch_m9s12x:
267       disassemble = print_insn_m9s12x;
268       break;
269     case bfd_arch_m9s12xg:
270       disassemble = print_insn_m9s12xg;
271       break;
272 #endif
273 #if defined(ARCH_s12z)
274     case bfd_arch_s12z:
275       disassemble = print_insn_s12z;
276       break;
277 #endif
278 #ifdef ARCH_m68k
279     case bfd_arch_m68k:
280       disassemble = print_insn_m68k;
281       break;
282 #endif
283 #ifdef ARCH_mt
284     case bfd_arch_mt:
285       disassemble = print_insn_mt;
286       break;
287 #endif
288 #ifdef ARCH_microblaze
289     case bfd_arch_microblaze:
290       disassemble = print_insn_microblaze;
291       break;
292 #endif
293 #ifdef ARCH_msp430
294     case bfd_arch_msp430:
295       disassemble = print_insn_msp430;
296       break;
297 #endif
298 #ifdef ARCH_nds32
299     case bfd_arch_nds32:
300       disassemble = print_insn_nds32;
301       break;
302 #endif
303 #ifdef ARCH_nfp
304     case bfd_arch_nfp:
305       disassemble = print_insn_nfp;
306       break;
307 #endif
308 #ifdef ARCH_ns32k
309     case bfd_arch_ns32k:
310       disassemble = print_insn_ns32k;
311       break;
312 #endif
313 #ifdef ARCH_mcore
314     case bfd_arch_mcore:
315       disassemble = print_insn_mcore;
316       break;
317 #endif
318 #ifdef ARCH_mep
319     case bfd_arch_mep:
320       disassemble = print_insn_mep;
321       break;
322 #endif
323 #ifdef ARCH_metag
324     case bfd_arch_metag:
325       disassemble = print_insn_metag;
326       break;
327 #endif
328 #ifdef ARCH_mips
329     case bfd_arch_mips:
330       if (big)
331 	disassemble = print_insn_big_mips;
332       else
333 	disassemble = print_insn_little_mips;
334       break;
335 #endif
336 #ifdef ARCH_mmix
337     case bfd_arch_mmix:
338       disassemble = print_insn_mmix;
339       break;
340 #endif
341 #ifdef ARCH_mn10200
342     case bfd_arch_mn10200:
343       disassemble = print_insn_mn10200;
344       break;
345 #endif
346 #ifdef ARCH_mn10300
347     case bfd_arch_mn10300:
348       disassemble = print_insn_mn10300;
349       break;
350 #endif
351 #ifdef ARCH_nios2
352     case bfd_arch_nios2:
353       if (big)
354 	disassemble = print_insn_big_nios2;
355       else
356 	disassemble = print_insn_little_nios2;
357       break;
358 #endif
359 #ifdef ARCH_or1k
360     case bfd_arch_or1k:
361       disassemble = print_insn_or1k;
362       break;
363 #endif
364 #ifdef ARCH_pdp11
365     case bfd_arch_pdp11:
366       disassemble = print_insn_pdp11;
367       break;
368 #endif
369 #ifdef ARCH_pj
370     case bfd_arch_pj:
371       disassemble = print_insn_pj;
372       break;
373 #endif
374 #ifdef ARCH_powerpc
375     case bfd_arch_powerpc:
376 #endif
377 #ifdef ARCH_rs6000
378     case bfd_arch_rs6000:
379 #endif
380 #if defined ARCH_powerpc || defined ARCH_rs6000
381       if (big)
382 	disassemble = print_insn_big_powerpc;
383       else
384 	disassemble = print_insn_little_powerpc;
385       break;
386 #endif
387 #ifdef ARCH_pru
388     case bfd_arch_pru:
389       disassemble = print_insn_pru;
390       break;
391 #endif
392 #ifdef ARCH_riscv
393     case bfd_arch_riscv:
394       disassemble = riscv_get_disassembler (abfd);
395       break;
396 #endif
397 #ifdef ARCH_rl78
398     case bfd_arch_rl78:
399       disassemble = rl78_get_disassembler (abfd);
400       break;
401 #endif
402 #ifdef ARCH_rx
403     case bfd_arch_rx:
404       disassemble = print_insn_rx;
405       break;
406 #endif
407 #ifdef ARCH_s390
408     case bfd_arch_s390:
409       disassemble = print_insn_s390;
410       break;
411 #endif
412 #ifdef ARCH_score
413     case bfd_arch_score:
414       if (big)
415 	disassemble = print_insn_big_score;
416       else
417 	disassemble = print_insn_little_score;
418      break;
419 #endif
420 #ifdef ARCH_sh
421     case bfd_arch_sh:
422       disassemble = print_insn_sh;
423       break;
424 #endif
425 #ifdef ARCH_sparc
426     case bfd_arch_sparc:
427       disassemble = print_insn_sparc;
428       break;
429 #endif
430 #ifdef ARCH_spu
431     case bfd_arch_spu:
432       disassemble = print_insn_spu;
433       break;
434 #endif
435 #ifdef ARCH_tic30
436     case bfd_arch_tic30:
437       disassemble = print_insn_tic30;
438       break;
439 #endif
440 #ifdef ARCH_tic4x
441     case bfd_arch_tic4x:
442       disassemble = print_insn_tic4x;
443       break;
444 #endif
445 #ifdef ARCH_tic54x
446     case bfd_arch_tic54x:
447       disassemble = print_insn_tic54x;
448       break;
449 #endif
450 #ifdef ARCH_tic6x
451     case bfd_arch_tic6x:
452       disassemble = print_insn_tic6x;
453       break;
454 #endif
455 #ifdef ARCH_ft32
456     case bfd_arch_ft32:
457       disassemble = print_insn_ft32;
458       break;
459 #endif
460 #ifdef ARCH_v850
461     case bfd_arch_v850:
462     case bfd_arch_v850_rh850:
463       disassemble = print_insn_v850;
464       break;
465 #endif
466 #ifdef ARCH_wasm32
467     case bfd_arch_wasm32:
468       disassemble = print_insn_wasm32;
469       break;
470 #endif
471 #ifdef ARCH_xgate
472     case bfd_arch_xgate:
473       disassemble = print_insn_xgate;
474       break;
475 #endif
476 #ifdef ARCH_xstormy16
477     case bfd_arch_xstormy16:
478       disassemble = print_insn_xstormy16;
479       break;
480 #endif
481 #ifdef ARCH_xtensa
482     case bfd_arch_xtensa:
483       disassemble = print_insn_xtensa;
484       break;
485 #endif
486 #ifdef ARCH_z80
487     case bfd_arch_z80:
488       disassemble = print_insn_z80;
489       break;
490 #endif
491 #ifdef ARCH_z8k
492     case bfd_arch_z8k:
493       if (mach == bfd_mach_z8001)
494 	disassemble = print_insn_z8001;
495       else
496 	disassemble = print_insn_z8002;
497       break;
498 #endif
499 #ifdef ARCH_vax
500     case bfd_arch_vax:
501       disassemble = print_insn_vax;
502       break;
503 #endif
504 #ifdef ARCH_visium
505      case bfd_arch_visium:
506        disassemble = print_insn_visium;
507        break;
508 #endif
509 #ifdef ARCH_frv
510     case bfd_arch_frv:
511       disassemble = print_insn_frv;
512       break;
513 #endif
514 #ifdef ARCH_moxie
515     case bfd_arch_moxie:
516       disassemble = print_insn_moxie;
517       break;
518 #endif
519 #ifdef ARCH_iq2000
520     case bfd_arch_iq2000:
521       disassemble = print_insn_iq2000;
522       break;
523 #endif
524 #ifdef ARCH_m32c
525     case bfd_arch_m32c:
526       disassemble = print_insn_m32c;
527       break;
528 #endif
529 #ifdef ARCH_tilegx
530     case bfd_arch_tilegx:
531       disassemble = print_insn_tilegx;
532       break;
533 #endif
534 #ifdef ARCH_tilepro
535     case bfd_arch_tilepro:
536       disassemble = print_insn_tilepro;
537       break;
538 #endif
539 #ifdef ARCH_loongarch
540     case bfd_arch_loongarch:
541       disassemble = print_insn_loongarch;
542       break;
543 #endif
544     default:
545       return 0;
546     }
547   return disassemble;
548 }
549 
550 void
551 disassembler_usage (FILE *stream ATTRIBUTE_UNUSED)
552 {
553 #ifdef ARCH_aarch64
554   print_aarch64_disassembler_options (stream);
555 #endif
556 #ifdef ARCH_arc
557   print_arc_disassembler_options (stream);
558 #endif
559 #ifdef ARCH_arm
560   print_arm_disassembler_options (stream);
561 #endif
562 #ifdef ARCH_mips
563   print_mips_disassembler_options (stream);
564 #endif
565 #ifdef ARCH_nfp
566   print_nfp_disassembler_options (stream);
567 #endif
568 #ifdef ARCH_powerpc
569   print_ppc_disassembler_options (stream);
570 #endif
571 #ifdef ARCH_riscv
572   print_riscv_disassembler_options (stream);
573 #endif
574 #ifdef ARCH_i386
575   print_i386_disassembler_options (stream);
576 #endif
577 #ifdef ARCH_kvx
578   print_kvx_disassembler_options (stream);
579 #endif
580 #ifdef ARCH_s390
581   print_s390_disassembler_options (stream);
582 #endif
583 #ifdef ARCH_wasm32
584   print_wasm32_disassembler_options (stream);
585 #endif
586 #ifdef ARCH_loongarch
587   print_loongarch_disassembler_options (stream);
588 #endif
589 #ifdef ARCH_bpf
590   print_bpf_disassembler_options (stream);
591 #endif
592   return;
593 }
594 
595 void
596 disassemble_init_for_target (struct disassemble_info * info)
597 {
598   if (info == NULL)
599     return;
600 
601   switch (info->arch)
602     {
603 #ifdef ARCH_aarch64
604     case bfd_arch_aarch64:
605       info->symbol_is_valid = aarch64_symbol_is_valid;
606       info->disassembler_needs_relocs = true;
607       info->created_styled_output = true;
608       break;
609 #endif
610 #ifdef ARCH_arc
611     case bfd_arch_arc:
612       info->created_styled_output = true;
613       break;
614 #endif
615 #ifdef ARCH_arm
616     case bfd_arch_arm:
617       info->symbol_is_valid = arm_symbol_is_valid;
618       info->disassembler_needs_relocs = true;
619       info->created_styled_output = true;
620       break;
621 #endif
622 #ifdef ARCH_avr
623     case bfd_arch_avr:
624       info->created_styled_output = true;
625       break;
626 #endif
627 #ifdef ARCH_csky
628     case bfd_arch_csky:
629       info->symbol_is_valid = csky_symbol_is_valid;
630       info->disassembler_needs_relocs = true;
631       break;
632 #endif
633 #ifdef ARCH_i386
634     case bfd_arch_i386:
635     case bfd_arch_iamcu:
636       info->created_styled_output = true;
637       break;
638 #endif
639 #ifdef ARCH_ia64
640     case bfd_arch_ia64:
641       info->skip_zeroes = 16;
642       break;
643 #endif
644 #ifdef ARCH_loongarch
645     case bfd_arch_loongarch:
646       info->created_styled_output = true;
647       break;
648 #endif
649 #ifdef ARCH_tic4x
650     case bfd_arch_tic4x:
651       info->skip_zeroes = 32;
652       break;
653 #endif
654 #ifdef ARCH_m68k
655     case bfd_arch_m68k:
656       info->created_styled_output = true;
657       break;
658 #endif
659 #ifdef ARCH_mep
660     case bfd_arch_mep:
661       info->skip_zeroes = 256;
662       info->skip_zeroes_at_end = 0;
663       break;
664 #endif
665 #ifdef ARCH_metag
666     case bfd_arch_metag:
667       info->disassembler_needs_relocs = true;
668       break;
669 #endif
670 #ifdef ARCH_mips
671     case bfd_arch_mips:
672       info->created_styled_output = true;
673       break;
674 #endif
675 #ifdef ARCH_m32c
676     case bfd_arch_m32c:
677       /* This processor in fact is little endian.  The value set here
678 	 reflects the way opcodes are written in the cgen description.  */
679       info->endian = BFD_ENDIAN_BIG;
680       if (!info->private_data)
681 	{
682 	  info->private_data = cgen_bitset_create (ISA_MAX);
683 	  if (info->mach == bfd_mach_m16c)
684 	    cgen_bitset_set (info->private_data, ISA_M16C);
685 	  else
686 	    cgen_bitset_set (info->private_data, ISA_M32C);
687 	}
688       break;
689 #endif
690 #ifdef ARCH_bpf
691     case bfd_arch_bpf:
692       info->created_styled_output = true;
693       break;
694 #endif
695 #ifdef ARCH_pru
696     case bfd_arch_pru:
697       info->disassembler_needs_relocs = true;
698       break;
699 #endif
700 #ifdef ARCH_powerpc
701     case bfd_arch_powerpc:
702 #endif
703 #ifdef ARCH_rs6000
704     case bfd_arch_rs6000:
705 #endif
706 #if defined (ARCH_powerpc) || defined (ARCH_rs6000)
707       disassemble_init_powerpc (info);
708       info->created_styled_output = true;
709       break;
710 #endif
711 #ifdef ARCH_riscv
712     case bfd_arch_riscv:
713       info->symbol_is_valid = riscv_symbol_is_valid;
714       info->created_styled_output = true;
715       break;
716 #endif
717 #ifdef ARCH_wasm32
718     case bfd_arch_wasm32:
719       disassemble_init_wasm32 (info);
720       break;
721 #endif
722 #ifdef ARCH_s390
723     case bfd_arch_s390:
724       disassemble_init_s390 (info);
725       info->created_styled_output = true;
726       break;
727 #endif
728 #ifdef ARCH_nds32
729     case bfd_arch_nds32:
730       disassemble_init_nds32 (info);
731       break;
732  #endif
733     default:
734       break;
735     }
736 }
737 
738 void
739 disassemble_free_target (struct disassemble_info *info)
740 {
741   if (info == NULL)
742     return;
743 
744   switch (info->arch)
745     {
746     default:
747       return;
748 
749 #ifdef ARCH_m32c
750     case bfd_arch_m32c:
751 #endif
752 #if defined ARCH_m32c
753       if (info->private_data)
754 	{
755 	  CGEN_BITSET *mask = info->private_data;
756 	  free (mask->bits);
757 	}
758       break;
759 #endif
760 
761 #ifdef ARCH_arc
762     case bfd_arch_arc:
763       break;
764 #endif
765 #ifdef ARCH_cris
766     case bfd_arch_cris:
767       break;
768 #endif
769 #ifdef ARCH_mmix
770     case bfd_arch_mmix:
771       break;
772 #endif
773 #ifdef ARCH_nfp
774     case bfd_arch_nfp:
775       break;
776 #endif
777 #ifdef ARCH_powerpc
778     case bfd_arch_powerpc:
779       break;
780 #endif
781 #ifdef ARCH_riscv
782     case bfd_arch_riscv:
783       disassemble_free_riscv (info);
784       break;
785 #endif
786 #ifdef ARCH_rs6000
787     case bfd_arch_rs6000:
788       break;
789 #endif
790     }
791 
792   free (info->private_data);
793 }
794 
795 /* Remove whitespace and consecutive commas from OPTIONS.  */
796 
797 char *
798 remove_whitespace_and_extra_commas (char *options)
799 {
800   char *str;
801   size_t i, len;
802 
803   if (options == NULL)
804     return NULL;
805 
806   /* Strip off all trailing whitespace and commas.  */
807   for (len = strlen (options); len > 0; len--)
808     {
809       if (!ISSPACE (options[len - 1]) && options[len - 1] != ',')
810 	break;
811       options[len - 1] = '\0';
812     }
813 
814   /* Convert all remaining whitespace to commas.  */
815   for (i = 0; options[i] != '\0'; i++)
816     if (ISSPACE (options[i]))
817       options[i] = ',';
818 
819   /* Remove consecutive commas.  */
820   for (str = options; *str != '\0'; str++)
821     if (*str == ',' && (*(str + 1) == ',' || str == options))
822       {
823 	char *next = str + 1;
824 	while (*next == ',')
825 	  next++;
826 	len = strlen (next);
827 	if (str != options)
828 	  str++;
829 	memmove (str, next, len);
830 	next[len - (size_t)(next - str)] = '\0';
831       }
832   return (strlen (options) != 0) ? options : NULL;
833 }
834 
835 /* Like STRCMP, but treat ',' the same as '\0' so that we match
836    strings like "foobar" against "foobar,xxyyzz,...".  */
837 
838 int
839 disassembler_options_cmp (const char *s1, const char *s2)
840 {
841   unsigned char c1, c2;
842 
843   do
844     {
845       c1 = (unsigned char) *s1++;
846       if (c1 == ',')
847 	c1 = '\0';
848       c2 = (unsigned char) *s2++;
849       if (c2 == ',')
850 	c2 = '\0';
851       if (c1 == '\0')
852 	return c1 - c2;
853     }
854   while (c1 == c2);
855 
856   return c1 - c2;
857 }
858 
859 void
860 opcodes_assert (const char *file, int line)
861 {
862   opcodes_error_handler (_("assertion fail %s:%d"), file, line);
863   opcodes_error_handler (_("Please report this bug"));
864   abort ();
865 }
866 
867 /* Set the stream, and the styled and unstyled printf functions within
868    INFO.  */
869 
870 void
871 disassemble_set_printf (struct disassemble_info *info, void *stream,
872 			fprintf_ftype unstyled_printf,
873 			fprintf_styled_ftype styled_printf)
874 {
875   info->stream = stream;
876   info->fprintf_func = unstyled_printf;
877   info->fprintf_styled_func = styled_printf;
878 }
879