discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with gnustep on OpenBSD sparc64


From: Sebastian Reitenbach
Subject: Re: problem with gnustep on OpenBSD sparc64
Date: Wed, 06 Jul 2011 14:44:39 +0200
User-agent: SOGoMail 1.3.7

Hi,


On Wednesday, July 6, 2011 14:21 CEST, David Chisnall <theraven@sucs.org> 
wrote: 
 
> On 6 Jul 2011, at 13:13, Sebastian Reitenbach wrote:
> 
> > Ivar type: [3[4i]], size: 0
> 
> 
> Well, that's obviously wrong, but I can't reproduce it.  We can, at least, 
> work from a simpler test case now though:
> 
> $ cat test.c
> #include <stdio.h>
> size_t objc_sizeof_type(const char*);
> 
> int main(void)
> {
>       printf("%d\n",  (int)objc_sizeof_type("[3[4i]]"));
>       return 0;
> }
> $ cc size.c -lobjc && ./a.out 
> 48

mine is looking a bit differently:

$ cc test.c -L/usr/local/lib -lobjc -pthread
$ ./a.out                                                                       
                                                                                
     
0
$ 

running it in gdb, I see the following:


$ gdb a.out                                                                     
                                                                                
     
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc64-unknown-openbsd4.9"...(no debugging symbols 
found)

(gdb) break objc_sizeof_type
Breakpoint 1 at 0x400ea0
(gdb) r
Starting program: /home/sebastia/a.out 
Breakpoint 1 at 0x204d65604: file encoding2.c, line 319.

Breakpoint 1, objc_sizeof_type (type=0x200c10 "[3[4i]]") at encoding2.c:319
319             sizeof_type(type, &size);
(gdb) list
314     }
315     
316     size_t objc_sizeof_type(const char *type)
317     {
318             size_t size = 0;
319             sizeof_type(type, &size);
320             return size / 8;
321     }
322     
323     size_t objc_alignof_type (const char *type)
(gdb) print type
$1 = 0x200c10 "[3[4i]]"
(gdb) s
sizeof_type (type=0x200c10 "[3[4i]]", size=0xfffffffffffdebd8) at 
encoding2.c:152
152             type = objc_skip_type_qualifiers(type);
(gdb) print
$2 = 0x200c10 "[3[4i]]"
(gdb) list
147     
148     static const char *sizeof_union_field(const char *type, size_t *size);
149     
150     static const char *sizeof_type(const char *type, size_t *size)
151     {
152             type = objc_skip_type_qualifiers(type);
153             switch (*type)
154             {
155                     // For all primitive types, we round up the current 
size to the
156                     // required alignment of the type, then add the size
(gdb) print *type
$3 = 91 '['
(gdb) list
157     #define APPLY_TYPE(typeName, name, capitalizedName, encodingChar) \
158                     case encodingChar:\
159                     {\
160                             round_up(size, (alignof(typeName) * 8));\
161                             *size += (sizeof(typeName) * 8);\
162                             return type + 1;\
163                     }
164     #define NON_INTEGER_TYPES 1
165     #include "type_encoding_cases.h"
166                     case '?':
(gdb) s
objc_skip_type_qualifiers (type=0x200c10 "[3[4i]]") at encoding2.c:20
20              while('\0' != *type && strchr(type_qualifiers, *type))
(gdb) list
15      #define alignof(type) __builtin_offsetof(struct { const char c; type 
member; }, member)
16      
17      const char *objc_skip_type_qualifiers (const char *type)
18      {
19              static const char *type_qualifiers = "rnNoORV";
20              while('\0' != *type && strchr(type_qualifiers, *type))
21              {
22                      type++;
23              }
24              return type;
(gdb) s
18      {
(gdb) 
0x0000000204d64c94 in objc_exception_throw () at encoding2.c:85
85      static void parse_struct_or_union(const char **type, type_parser 
callback, void *context, char endchar)
(gdb) list 
80              // skip ]
81              (*type)++;
82              return element_count;
83      }
84      
85      static void parse_struct_or_union(const char **type, type_parser 
callback, void *context, char endchar)
86      {
87              // Skip the ( and structure name
88              do
89              {
(gdb) s
0x0000000204d64c98      85      static void parse_struct_or_union(const char 
**type, type_parser callback, void *context, char endchar)
(gdb) s
objc_skip_type_qualifiers (type=0x200c10 "[3[4i]]") at encoding2.c:20
20              while('\0' != *type && strchr(type_qualifiers, *type))
(gdb) 
strchr (p=0x204e74c68 "rnNoORV", ch=91) at /usr/src/lib/libc/string/index.c:41
41      /usr/src/lib/libc/string/index.c: No such file or directory.
        in /usr/src/lib/libc/string/index.c
(gdb) 
39      in /usr/src/lib/libc/string/index.c
(gdb) n
0x00000002054416c0 in getenv () at /usr/src/lib/libc/string/index.c:38
38      in /usr/src/lib/libc/string/index.c
(gdb) 
0x00000002054416c4      38      in /usr/src/lib/libc/string/index.c
(gdb) 
strchr (p=0x204e74c68 "rnNoORV", ch=91) at /usr/src/lib/libc/string/index.c:41
41      in /usr/src/lib/libc/string/index.c
(gdb) 
43      in /usr/src/lib/libc/string/index.c
(gdb) 
43      in /usr/src/lib/libc/string/index.c
(gdb) 
43      in /usr/src/lib/libc/string/index.c
(gdb) 
43      in /usr/src/lib/libc/string/index.c
(gdb) 
43      in /usr/src/lib/libc/string/index.c
(gdb) 
43      in /usr/src/lib/libc/string/index.c
(gdb) 
43      in /usr/src/lib/libc/string/index.c
(gdb) 
43      in /usr/src/lib/libc/string/index.c
(gdb) 
47      in /usr/src/lib/libc/string/index.c
(gdb) 
objc_skip_type_qualifiers (type=0x200c10 "[3[4i]]") at encoding2.c:20
20              while('\0' != *type && strchr(type_qualifiers, *type))
(gdb) 
25      }
(gdb) 
sizeof_type (type=0x200c10 "[3[4i]]", size=0xfffffffffffdebd8) at 
encoding2.c:153
153             switch (*type)
(gdb) 
196                             int element_count = parse_array(&t, 
(type_parser)sizeof_type, &element_size);
(gdb) list
191                     case '[':
192                     {
193                             const char *t = type;
194                             int element_size = 0;
195                             // FIXME: aligned size
196                             int element_count = parse_array(&t, 
(type_parser)sizeof_type, &element_size);
197                             (*size) += element_size * element_count;
198                             return t;
199                     }
200                     case '(':
(gdb) print t
Variable "t" is not available.
(gdb) print *t
Variable "t" is not available.
(gdb) print type
$4 = 0x200c10 "[3[4i]]"
(gdb) s
193                             const char *t = type;
(gdb) 
196                             int element_count = parse_array(&t, 
(type_parser)sizeof_type, &element_size);
(gdb) 
194                             int element_size = 0;
(gdb) list
189                             return t;
190                     }
191                     case '[':
192                     {
193                             const char *t = type;
194                             int element_size = 0;
195                             // FIXME: aligned size
196                             int element_count = parse_array(&t, 
(type_parser)sizeof_type, &element_size);
197                             (*size) += element_size * element_count;
198                             return t;
(gdb) s
196                             int element_count = parse_array(&t, 
(type_parser)sizeof_type, &element_size);
(gdb) 
parse_array (type=0xfffffffffffdeb08, callback=0x204d652a0 <sizeof_type>, 
context=0xfffffffffffdeb00) at encoding2.c:77
77              (*type)++;
(gdb) list
72      typedef const char *(*type_parser)(const char*, void*);
73      
74      static int parse_array(const char **type, type_parser callback, void 
*context)
75      {
76              // skip [
77              (*type)++;
78              int element_count = (int)strtol(*type, (char**)type, 10);
79              *type = callback(*type, context);
80              // skip ]
81              (*type)++;
(gdb) print type
$5 = (const char **) 0xfffffffffffdeb08
(gdb) print *type
$6 = 0x200c10 "[3[4i]]"
(gdb) s
78              int element_count = (int)strtol(*type, (char**)type, 10);
(gdb) print *type
$7 = 0x200c10 "[3[4i]]"
(gdb) s
75      {
(gdb) list
70      
71      
72      typedef const char *(*type_parser)(const char*, void*);
73      
74      static int parse_array(const char **type, type_parser callback, void 
*context)
75      {
76              // skip [
77              (*type)++;
78              int element_count = (int)strtol(*type, (char**)type, 10);
79              *type = callback(*type, context);
(gdb) print element_count
No symbol "element_count" in current context.
(gdb) s
77              (*type)++;
(gdb) 
78              int element_count = (int)strtol(*type, (char**)type, 10);
(gdb) print type
$8 = (const char **) 0xfffffffffffdeb08
(gdb) print *type
$9 = 0x200c10 "[3[4i]]"
(gdb) s
strtol (nptr=0x200c11 "3[4i]]", endptr=0xfffffffffffdeb08, base=10) at 
ctype.h:133
133             return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _S));
(gdb) list
128             return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _P));
129     }
130     
131     __only_inline int isspace(int c)
132     {
133             return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _S));
134     }
135     
136     __only_inline int isupper(int c)
137     {
(gdb) s
45      /usr/src/lib/libc/stdlib/strtol.c: No such file or directory.
        in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
0x0000000205424a20 in strpbrk () at /usr/src/lib/libc/stdlib/strtol.c:44
44      in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
0x0000000205424a24      44      in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
strtol (nptr=0x200c11 "3[4i]]", endptr=0xfffffffffffdeb08, base=10) at 
ctype.h:133
133             return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _S));
(gdb) 
58      /usr/src/lib/libc/stdlib/strtol.c: No such file or directory.
        in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
133             return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _S));
(gdb) 
59      /usr/src/lib/libc/stdlib/strtol.c: No such file or directory.
        in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
60      in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
65      in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
68      in /usr/src/lib/libc/stdlib/strtol.c
(gdb) n
74      in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
94      in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
95      in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
96      in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
129     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
102     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
119     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
102     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
129     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
105     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
111     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
113     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
115     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
126     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
133     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
104     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
133     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
104     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
105     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
98              return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & 
(_U|_L)));
(gdb) 
107     /usr/src/lib/libc/stdlib/strtol.c: No such file or directory.
        in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
137     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
138     in /usr/src/lib/libc/stdlib/strtol.c
(gdb) 
parse_array (type=0xfffffffffffdeb08, callback=0x204d652a0 <sizeof_type>, 
context=0xfffffffffffdeb00) at encoding2.c:79
79              *type = callback(*type, context);
(gdb) 
81              (*type)++;
(gdb) 
83      }
(gdb) list
78              int element_count = (int)strtol(*type, (char**)type, 10);
79              *type = callback(*type, context);
80              // skip ]
81              (*type)++;
82              return element_count;
83      }
84      
85      static void parse_struct_or_union(const char **type, type_parser 
callback, void *context, char endchar)
86      {
87              // Skip the ( and structure name
(gdb) 
88              do
89              {
90                      (*type)++;
91                      // Opaque type has no =definition
92                      if (endchar == **type) { (*type)++; return; }
93              } while('=' != **type);
94              // Skip =
95              (*type)++;
96      
97              while (**type != endchar)
(gdb) print type
$10 = (const char **) 0xfffffffffffdeb08
(gdb) print *type
$11 = 0x200c17 ""
(gdb) n
sizeof_type (type=0x200c10 "[3[4i]]", size=0xfffffffffffdebd8) at 
encoding2.c:198
198                             return t;
(gdb) print t
$12 = 0x200c17 ""
(gdb) s
197                             (*size) += element_size * element_count;
(gdb) print element_size
$13 = 0
(gdb) print element_count
No symbol "element_count" in current context.
(gdb) s
objc_sizeof_type (type=0x200c10 "[3[4i]]") at encoding2.c:321
321     }
(gdb) list
316     size_t objc_sizeof_type(const char *type)
317     {
318             size_t size = 0;
319             sizeof_type(type, &size);
320             return size / 8;
321     }
322     
323     size_t objc_alignof_type (const char *type)
324     {
325             size_t align = 0;
(gdb) print size
$14 = 0
(gdb)


in the strtol manual page I read:
RETURN VALUES
     The strtol(), strtoll(), strtoimax(), and strtoq() functions return the
     result of the conversion, unless the value would underflow or overflow.
     If no conversion could be performed, 0 is returned;

Does that mean now that there is no conversion done on that string?

Sebastian


> 
> On SPARC64, I think sizeof(int) is 8, so I'd expect this to be 96.  If it 
> isn't, we need to work out why.  Can you step through this call and see if 
> it's doing anything obviously wrong?
> 
> David
> 
> -- Sent from my PDP-11
> 
 
 
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]