Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] add union & bitfield to sv_flags for easier dump analysis #13864

Closed
p5pRT opened this issue May 20, 2014 · 13 comments
Closed

[PATCH] add union & bitfield to sv_flags for easier dump analysis #13864

p5pRT opened this issue May 20, 2014 · 13 comments

Comments

@p5pRT
Copy link

p5pRT commented May 20, 2014

Migrated from rt.perl.org#121932 (status was 'rejected')

Searchable as RT121932$

@p5pRT
Copy link
Author

p5pRT commented May 20, 2014

From @bulk88

Created by @bulk88

See attached patch.

Perl Info

Flags:
      category=core
      severity=low

Site configuration information for perl 5.20.0:

Configured by Owner at Sat May 17 23:49:31 2014.

Summary of my perl5 (revision 5 version 20 subversion 0) configuration:
    Local Commit: 5b1fb5914dd2ffb35ae3286bcf8e8ee236940710
    Ancestor: e023b52d29900981e0c68349b3ec306d85c0716d
    Platform:
      osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
      uname=''
      config_args='undef'
      hint=recommended, useposix=true, d_sigaction=undef
      useithreads=define, usemultiplicity=define
      use64bitint=undef, use64bitall=undef, uselongdouble=undef
      usemymalloc=n, bincompat5005=undef
    Compiler:
      cc='cl', ccflags ='-nologo -GF -W3 -O1 -MD -Zi -DNDEBUG -G7 -GL
-DWIN32 -D_CONSOLE -DNO_STRICT  -DPERL_TEXTMODE_SCRIPTS
-DPERL_HASH_FUNC_ONE_AT_A_TIME -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T',
      optimize='-O1 -MD -Zi -DNDEBUG -G7 -GL',
      cppflags='-DWIN32'
      ccversion='13.10.6030', gccversion='', gccosandvers=''
      intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
      d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
      ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64',
lseeksize=8
      alignbytes=8, prototype=define
    Linker and Libraries:
      ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf
-ltcg  -libpath:"c:\perl519\lib\CORE"  -machine:x86'
      libpth="C:\Program Files\Microsoft Visual Studio .NET 2003\VC7\lib"
      libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib
odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
      perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
      libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl520.lib
      gnulibc_version=''
    Dynamic Linking:
      dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
      cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-opt:ref,icf -ltcg  -libpath:"c:\perl519\lib\CORE"  -machine:x86'

Locally applied patches:
      RC1
      602f5d5ad824f3fd87b13b2613c3ff8ea5321bf8
      7e81d5c4f446d69f52760d5f05e193bbed8cd3db
      5b1fb5914dd2ffb35ae3286bcf8e8ee236940710


@INC for perl 5.20.0:
      C:/perl519/site/lib
      C:/perl519/lib
      .


Environment for perl 5.20.0:
      HOME (unset)
      LANG (unset)
      LANGUAGE (unset)
      LD_LIBRARY_PATH (unset)
      LOGDIR (unset)
      PATH=C:\perl519\bin;C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\IDE;C:\Program Files\Microsoft Visual Studio .NET
2003\VC7\BIN;C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\Tools;C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\Tools\bin\prerelease;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\wbem;
      PERL_BADLANG (unset)
      SHELL (unset)




@p5pRT
Copy link
Author

p5pRT commented May 20, 2014

From @bulk88

0001-add-union-bitfield-to-sv_flags-for-easier-dump-analy.patch
From a0d45eb0495c33b3cba0a71c1e67787af30a6352 Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Tue, 20 May 2014 18:58:22 -0400
Subject: [PATCH] add union & bitfield to sv_flags for easier dump analysis

Calling Perl_dump_sv from a C debugger on demand on a SV* is not always
possible, if all threads in the process are frozen, it segv'ed or is a
dump file (not a process), or PerlIO/interp struct is in a partial state
and can't print to the console. So create this bitfield on compilers that
support anon unions to make looking at the sv head easier.
---
 sv.h          |   41 ++++++++++++++++++++++++++++++++++++++++-
 win32/win32.h |    2 ++
 2 files changed, 42 insertions(+), 1 deletions(-)

diff --git a/sv.h b/sv.h
index 6332974..495b315 100644
--- a/sv.h
+++ b/sv.h
@@ -186,10 +186,46 @@ typedef struct hek HEK;
 /* Using C's structural equivalence to help emulate C++ inheritance here... */
 
 /* start with 2 sv-head building blocks */
-#define _SV_HEAD(ptrtype) \
+#ifndef HAS_ANONFIELDS
+# define _SV_HEAD(ptrtype) \
     ptrtype	sv_any;		/* pointer to body */	\
     U32		sv_refcnt;	/* how many references to us */	\
     U32		sv_flags	/* what we are */
+#else
+# define _SV_HEAD(ptrtype) \
+    ptrtype	sv_any;		/* pointer to body */	\
+    U32		sv_refcnt;	/* how many references to us */	\
+    union {\
+        U32	sv_flags;	/* what we are */ \
+        struct { \
+            unsigned long type : 8; \
+            unsigned long f_IOK : 1; \
+            unsigned long f_NOK : 1; \
+            unsigned long f_POK : 1; \
+            unsigned long f_ROK : 1; \
+            unsigned long p_IOK: 1; \
+            unsigned long p_NOK: 1; \
+            unsigned long p_POK : 1; \
+            unsigned long p_SCREAM_phv_CLONEABLE_pgv_GP_prv_PCS_IMPORTED_pad_NAMELIST : 1; \
+            unsigned long f_IsCOW : 1; \
+            unsigned long s_PADTMP_s_PADSTALE_pad_TYPED : 1; \
+            unsigned long s_PADMY_pad_OUR : 1; \
+            unsigned long s_TEMP : 1; \
+            unsigned long s_OBJECT : 1; \
+            unsigned long s_GMG : 1; \
+            unsigned long s_SMG : 1; \
+            unsigned long s_RMG : 1; \
+            unsigned long f_FAKE : 1; \
+            unsigned long f_OOK : 1; \
+            unsigned long f_BREAK: 1; \
+            unsigned long f_READONLY : 1; \
+            unsigned long f_AMAGIC : 1; \
+            unsigned long f_UTF8_phv_SHAREKEYS : 1; \
+            unsigned long pav_REAL_phv_LAZYDEL_pbm_VALID_repl_EVAL : 1; \
+            unsigned long f_IVisUV_pav_REIFY_phv_HASKFLAGS_pbm_TAIL_prv_WEAKREF_pad_STATE : 1; \
+        } flags_dbg; \
+    }
+#endif
 
 #define _SV_HEAD_UNION \
     union {				\
@@ -346,6 +382,9 @@ perform the upgrade if necessary.  See C<svtype>.
 #define SvUPGRADE(sv, mt) \
     ((void)(SvTYPE(sv) >= (mt) || (sv_upgrade(sv, mt),1)))
 
+
+/* *** If you edit any flags remember to update the bitfield above *** */
+
 #define SVf_IOK		0x00000100  /* has valid public integer value */
 #define SVf_NOK		0x00000200  /* has valid public numeric value */
 #define SVf_POK		0x00000400  /* has valid public pointer value */
diff --git a/win32/win32.h b/win32/win32.h
index 8db0303..bfb276f 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -264,6 +264,8 @@ typedef unsigned short	mode_t;
 #  pragma intrinsic(_rotl64,_rotr64)
 #endif
 
+#define HAS_ANONFIELDS
+
 #endif /* _MSC_VER */
 
 #ifdef __MINGW32__		/* Minimal Gnu-Win32 */
-- 
1.7.9.msysgit.0

@p5pRT
Copy link
Author

p5pRT commented May 20, 2014

From @bulk88

Better patch attached, purpose of the BF is now in src.

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT
Copy link
Author

p5pRT commented May 20, 2014

From @bulk88

0001-add-union-bitfield-to-sv_flags-for-easier-dump-analy.patch
From 5a929075ff177c67e0597757bd279eb28725f7ae Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Tue, 20 May 2014 19:14:27 -0400
Subject: [PATCH] add union & bitfield to sv_flags for easier dump analysis

Calling Perl_dump_sv from a C debugger on demand on a SV* is not always
possible, if all threads in the process are frozen, it segv'ed or is a
dump file (not a process), or PerlIO/interp struct is in a partial state
and can't print to the console. So create this bitfield on compilers that
support anon unions to make looking at the sv head easier. I expect more
compiler will enable HAS_ANONFIELDS on them in the future.
---
 sv.h          |   43 ++++++++++++++++++++++++++++++++++++++++++-
 win32/win32.h |    2 ++
 2 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/sv.h b/sv.h
index 6332974..1ccb06c 100644
--- a/sv.h
+++ b/sv.h
@@ -186,10 +186,48 @@ typedef struct hek HEK;
 /* Using C's structural equivalence to help emulate C++ inheritance here... */
 
 /* start with 2 sv-head building blocks */
-#define _SV_HEAD(ptrtype) \
+#ifndef HAS_ANONFIELDS
+# define _SV_HEAD(ptrtype) \
     ptrtype	sv_any;		/* pointer to body */	\
     U32		sv_refcnt;	/* how many references to us */	\
     U32		sv_flags	/* what we are */
+#else
+# define _SV_HEAD(ptrtype) \
+    ptrtype	sv_any;		/* pointer to body */	\
+    U32		sv_refcnt;	/* how many references to us */	\
+    union {\
+	U32	sv_flags;	/* what we are */	\
+	/* NEVER USE THE BITFIELD, its strictly for C debugger tools */	\
+	struct { \
+	    unsigned long type : 8; \
+	    unsigned long f_IOK : 1; \
+	    unsigned long f_NOK : 1; \
+	    unsigned long f_POK : 1; \
+	    unsigned long f_ROK : 1; \
+	    unsigned long p_IOK: 1; \
+	    unsigned long p_NOK: 1; \
+	    unsigned long p_POK : 1; \
+	    unsigned long p_SCREAM_phv_CLONEABLE_pgv_GP_prv_PCS_IMPORTED_pad_NAMELIST : 1; \
+	    unsigned long f_IsCOW : 1; \
+	    unsigned long s_PADTMP_s_PADSTALE_pad_TYPED : 1; \
+	    unsigned long s_PADMY_pad_OUR : 1; \
+	    unsigned long s_TEMP : 1; \
+	    unsigned long s_OBJECT : 1; \
+	    unsigned long s_GMG : 1; \
+	    unsigned long s_SMG : 1; \
+	    unsigned long s_RMG : 1; \
+	    unsigned long f_FAKE : 1; \
+	    unsigned long f_OOK : 1; \
+	    unsigned long f_BREAK: 1; \
+	    unsigned long f_READONLY : 1; \
+	    unsigned long f_AMAGIC : 1; \
+	    unsigned long f_UTF8_phv_SHAREKEYS : 1; \
+	    unsigned long pav_REAL_phv_LAZYDEL_pbm_VALID_repl_EVAL : 1; \
+	    unsigned long f_IVisUV_pav_REIFY_phv_HASKFLAGS_pbm_TAIL_prv_WEAKREF_pad_STATE : 1; \
+	} flags_dbg; \
+	/* NEVER USE THE BITFIELD, its strictly for C debugger tools */	\
+    }
+#endif
 
 #define _SV_HEAD_UNION \
     union {				\
@@ -346,6 +384,9 @@ perform the upgrade if necessary.  See C<svtype>.
 #define SvUPGRADE(sv, mt) \
     ((void)(SvTYPE(sv) >= (mt) || (sv_upgrade(sv, mt),1)))
 
+
+/* *** If you edit any flags remember to update the bitfield above *** */
+
 #define SVf_IOK		0x00000100  /* has valid public integer value */
 #define SVf_NOK		0x00000200  /* has valid public numeric value */
 #define SVf_POK		0x00000400  /* has valid public pointer value */
diff --git a/win32/win32.h b/win32/win32.h
index 8db0303..bfb276f 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -264,6 +264,8 @@ typedef unsigned short	mode_t;
 #  pragma intrinsic(_rotl64,_rotr64)
 #endif
 
+#define HAS_ANONFIELDS
+
 #endif /* _MSC_VER */
 
 #ifdef __MINGW32__		/* Minimal Gnu-Win32 */
-- 
1.7.9.msysgit.0

@p5pRT
Copy link
Author

p5pRT commented May 26, 2014

From @bulk88

On Tue May 20 16​:03​:31 2014, bulk88 wrote​:

This is a bug report for perl from bulk88@​hotmail.com,
generated with the help of perlbug 1.40 running under perl 5.20.0.

-----------------------------------------------------------------
[Please describe your issue here]

See attached patch.

Revised patched attached, tests + more features.

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT
Copy link
Author

p5pRT commented May 26, 2014

From @bulk88

0001-add-unions-bitfield-to-SV-for-easier-dump-analysis.patch
From 06d5c566f02a03a0d075e33bf90f137b7bb0d102 Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Mon, 26 May 2014 04:10:48 -0400
Subject: [PATCH] add unions & bitfield to SV for easier dump analysis

Calling Perl_dump_sv from a C debugger on demand on a SV* is not always
possible, if all threads in the process are frozen, it segv'ed or is a
dump file (not a process), or PerlIO/interp struct is in a partial state
and can't print to the console. So create this bitfield and any union
on compilers that support anon unions to make looking at the sv head
and body easier.  I expect more compiler will enable HAS_ANONFIELDS
on them in the future. This code was written to be particularly
useful with MS VS IDE's C debugger.
---
 ext/XS-APItest/APItest.pm |    2 +-
 ext/XS-APItest/APItest.xs |   24 +++++++++++++++++
 ext/XS-APItest/t/svpv.t   |    4 ++-
 sv.h                      |   61 ++++++++++++++++++++++++++++++++++++++++++++-
 win32/win32.h             |    2 +
 5 files changed, 90 insertions(+), 3 deletions(-)

diff --git a/ext/XS-APItest/APItest.pm b/ext/XS-APItest/APItest.pm
index 8c72b35..e17e263 100644
--- a/ext/XS-APItest/APItest.pm
+++ b/ext/XS-APItest/APItest.pm
@@ -5,7 +5,7 @@ use strict;
 use warnings;
 use Carp;
 
-our $VERSION = '0.60';
+our $VERSION = '0.61';
 
 require XSLoader;
 
diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs
index a51924d..5b6d341 100644
--- a/ext/XS-APItest/APItest.xs
+++ b/ext/XS-APItest/APItest.xs
@@ -1777,6 +1777,30 @@ xop_from_custom_op ()
     OUTPUT:
         RETVAL
 
+bool
+test_sv_debug_members()
+CODE:
+#ifdef HAS_ANONFIELDS
+    if(STRUCT_OFFSET(SV,sv_any) == STRUCT_OFFSET(SV,any_dbg._1_5iv)) {
+        SV * sv =  newSV(0);
+        if(!cBOOL(SvTEMP(sv)) && !sv->flags_dbg.s_TEMP) {
+            sv_2mortal(sv);
+            if(cBOOL(SvTEMP(sv)) && sv->flags_dbg.s_TEMP){
+                RETVAL = TRUE;
+                goto end;
+            }
+        } else { /* has to be freed even if failed */
+            sv_2mortal(sv);
+        }
+    }
+    RETVAL = FALSE;
+#else
+    RETVAL = TRUE; /* nothing to test, members don't exist */
+#endif
+    end:
+OUTPUT:
+    RETVAL
+
 BOOT:
 {
     MY_CXT_INIT;
diff --git a/ext/XS-APItest/t/svpv.t b/ext/XS-APItest/t/svpv.t
index 4602891..45fd71f 100644
--- a/ext/XS-APItest/t/svpv.t
+++ b/ext/XS-APItest/t/svpv.t
@@ -1,9 +1,11 @@
 #!perl -w
 
-use Test::More tests => 19;
+use Test::More tests => 20;
 
 use XS::APItest;
 
+ok(XS::APItest::test_sv_debug_members(), "debugging SV union members work");
+
 for my $func ('SvPVbyte', 'SvPVutf8') {
  $g = *glob;
  $r = \1;
diff --git a/sv.h b/sv.h
index 6332974..dcbd040 100644
--- a/sv.h
+++ b/sv.h
@@ -186,10 +186,66 @@ typedef struct hek HEK;
 /* Using C's structural equivalence to help emulate C++ inheritance here... */
 
 /* start with 2 sv-head building blocks */
-#define _SV_HEAD(ptrtype) \
+#ifndef HAS_ANONFIELDS
+# define _SV_HEAD(ptrtype) \
     ptrtype	sv_any;		/* pointer to body */	\
     U32		sv_refcnt;	/* how many references to us */	\
     U32		sv_flags	/* what we are */
+#else
+# define _SV_HEAD(ptrtype) \
+    union { \
+	ptrtype	sv_any;		/* pointer to body */	\
+	/* for use with a C debugger, numbers correspond to svtype */	\
+	union {			\
+	    XPVIV * _1_5iv;	\
+	    XPVNV * _2_6nv;	\
+	    XPV * _3pv;		\
+	    XINVLIST * _4invl;	\
+	    XPVMG * _7mg;	\
+	    struct regexp *_8rx;\
+	    XPVGV * _9gv;	\
+	    XPVLV * _10lv;	\
+	    XPVAV * _11av;	\
+	    XPVHV * _12hv;	\
+	    XPVCV * _13cv;	\
+	    XPVFM * _14fm;	\
+	    XPVIO * _15io;	\
+	} any_dbg;		\
+    }; \
+    U32		sv_refcnt;	/* how many references to us */	\
+    union {\
+	U32	sv_flags;	/* what we are */	\
+	/* NEVER USE THE BITFIELD, its strictly for C debugger tools */	\
+	struct { \
+	    unsigned long type : 8; \
+	    unsigned long f_IOK : 1; \
+	    unsigned long f_NOK : 1; \
+	    unsigned long f_POK : 1; \
+	    unsigned long f_ROK : 1; \
+	    unsigned long p_IOK: 1; \
+	    unsigned long p_NOK: 1; \
+	    unsigned long p_POK : 1; \
+	    unsigned long p_SCREAM_phv_CLONEABLE_pgv_GP_prv_PCS_IMPORTED_pad_NAMELIST : 1; \
+	    unsigned long f_IsCOW : 1; \
+	    unsigned long s_PADTMP_s_PADSTALE_pad_TYPED : 1; \
+	    unsigned long s_PADMY_pad_OUR : 1; \
+	    unsigned long s_TEMP : 1; \
+	    unsigned long s_OBJECT : 1; \
+	    unsigned long s_GMG : 1; \
+	    unsigned long s_SMG : 1; \
+	    unsigned long s_RMG : 1; \
+	    unsigned long f_FAKE : 1; \
+	    unsigned long f_OOK : 1; \
+	    unsigned long f_BREAK: 1; \
+	    unsigned long f_READONLY : 1; \
+	    unsigned long f_AMAGIC : 1; \
+	    unsigned long f_UTF8_phv_SHAREKEYS : 1; \
+	    unsigned long pav_REAL_phv_LAZYDEL_pbm_VALID_repl_EVAL : 1; \
+	    unsigned long f_IVisUV_pav_REIFY_phv_HASKFLAGS_pbm_TAIL_prv_WEAKREF_pad_STATE : 1; \
+	} flags_dbg; \
+	/* NEVER USE THE BITFIELD, its strictly for C debugger tools */	\
+    }
+#endif
 
 #define _SV_HEAD_UNION \
     union {				\
@@ -346,6 +402,9 @@ perform the upgrade if necessary.  See C<svtype>.
 #define SvUPGRADE(sv, mt) \
     ((void)(SvTYPE(sv) >= (mt) || (sv_upgrade(sv, mt),1)))
 
+
+/* *** If you edit any flags remember to update the bitfield above *** */
+
 #define SVf_IOK		0x00000100  /* has valid public integer value */
 #define SVf_NOK		0x00000200  /* has valid public numeric value */
 #define SVf_POK		0x00000400  /* has valid public pointer value */
diff --git a/win32/win32.h b/win32/win32.h
index 8db0303..bfb276f 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -264,6 +264,8 @@ typedef unsigned short	mode_t;
 #  pragma intrinsic(_rotl64,_rotr64)
 #endif
 
+#define HAS_ANONFIELDS
+
 #endif /* _MSC_VER */
 
 #ifdef __MINGW32__		/* Minimal Gnu-Win32 */
-- 
1.7.9.msysgit.0

@p5pRT
Copy link
Author

p5pRT commented May 27, 2014

From @iabyn

On Mon, May 26, 2014 at 01​:14​:01AM -0700, bulk88 via RT wrote​:

Revised patched attached, tests + more features.

Sorry, but I'm going to have to say that I don't like this idea.

While I like the idea of debuggers being able to display the bits of
sv_flags, I don't think the extra complexity is worth it. The definition
of an SV in sv.h is already a confusing mess of macros and unions, and I
don't like the idea of adding to the confusion. And in particular I don't
like the idea that that you now have to remember to change things in yet
another place if you ever update the flag bits.

--
Monto Blanco... scorchio!

@p5pRT
Copy link
Author

p5pRT commented May 27, 2014

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2014

From @nwc10

On Tue, May 27, 2014 at 12​:24​:16PM +0100, Dave Mitchell wrote​:

On Mon, May 26, 2014 at 01​:14​:01AM -0700, bulk88 via RT wrote​:

Revised patched attached, tests + more features.

Sorry, but I'm going to have to say that I don't like this idea.

While I like the idea of debuggers being able to display the bits of
sv_flags, I don't think the extra complexity is worth it. The definition
of an SV in sv.h is already a confusing mess of macros and unions, and I
don't like the idea of adding to the confusion. And in particular I don't
like the idea that that you now have to remember to change things in yet
another place if you ever update the flag bits.

I can't remember how much flexibility implementations have as to which way
to lay out bitfields. I can find at least two.

This is gcc on Linux​:

$ ./bitfield
i = 0x00000000, low=0 , middle=0 , high=0
i = 0x00000001, low=4294967295, middle=0 , high=0
i = 0x80000001, low=4294967295, middle=0 , high=4294967295
i = 0x80000000, low=0 , middle=0 , high=4294967295

This is gcc on Linux​:

$ ./bitfield
i = 0x00000000, low=0 , middle=0 , high=0
i = 0x80000000, low=4294967295, middle=0 , high=0
i = 0x80000001, low=4294967295, middle=0 , high=4294967295
i = 0x00000001, low=0 , middle=0 , high=4294967295

(One is x86_64, one is ppc64)

So there would need to be (at least) two bitfield layouts provided to match
the current explicit bitshifts.

Test program attached.

I think that that makes the currently proposed approach a non-starter.
Sorry.

There might be a way to do this, with one master source and regen scripts,
but I'm not sure how easy it is to be reliably portable.

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2014

From @nwc10

#include <stdio.h>
#include <stdint.h>

union test {
    int32_t i;
    struct {
        int low : 1;
        int middle : 30;
        int high : 1;
    } s;
} t;

void state() {
    printf("i = 0x%08x, low=%-10u, middle=%-10u, high=%-10u\n",
           t.i, t.s.low, t.s.middle, t.s.high);
} 
int main() {
    t.i = 0;
    state();
    t.s.low = 1;
    state();
    t.s.high = 1;
    state();
    t.s.low = 0;
    state();
    return 0;
}

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2014

From @Tux

On Wed, 4 Jun 2014 15​:37​:37 +0100, Nicholas Clark <nick@​ccl4.org> wrote​:

On Tue, May 27, 2014 at 12​:24​:16PM +0100, Dave Mitchell wrote​:

On Mon, May 26, 2014 at 01​:14​:01AM -0700, bulk88 via RT wrote​:

Revised patched attached, tests + more features.

Sorry, but I'm going to have to say that I don't like this idea.

While I like the idea of debuggers being able to display the bits of
sv_flags, I don't think the extra complexity is worth it. The definition
of an SV in sv.h is already a confusing mess of macros and unions, and I
don't like the idea of adding to the confusion. And in particular I don't
like the idea that that you now have to remember to change things in yet
another place if you ever update the flag bits.

I can't remember how much flexibility implementations have as to which way
to lay out bitfields. I can find at least two.

This is gcc on Linux​:

$ ./bitfield
i = 0x00000000, low=0 , middle=0 , high=0
i = 0x00000001, low=4294967295, middle=0 , high=0
i = 0x80000001, low=4294967295, middle=0 , high=4294967295
i = 0x80000000, low=0 , middle=0 , high=4294967295

This is gcc on Linux​:

$ ./bitfield
i = 0x00000000, low=0 , middle=0 , high=0
i = 0x80000000, low=4294967295, middle=0 , high=0
i = 0x80000001, low=4294967295, middle=0 , high=4294967295
i = 0x00000001, low=0 , middle=0 , high=4294967295

(One is x86_64, one is ppc64)

AIX 5.3.0.0/ML12 IBM,9115-505 PowerPC_POWER5/1898(2)

xlc/64
bitfield​: 64-bit XCOFF executable or object module not stripped

i = 0x00000000, low=0 , middle=0 , high=0
i = 0x80000000, low=1 , middle=0 , high=0
i = 0x80000001, low=1 , middle=0 , high=1
i = 0x00000001, low=0 , middle=0 , high=1

gcc/64
bitfield​: 64-bit XCOFF executable or object module not stripped

i = 0x00000000, low=0 , middle=0 , high=0
i = 0x80000000, low=4294967295, middle=0 , high=0
i = 0x80000001, low=4294967295, middle=0 , high=4294967295
i = 0x00000001, low=0 , middle=0 , high=4294967295

HP-UX 11.31/64 U rx2660/64 Itanium 2 9100/1710(2) ia64 4075 Mb

HP C-ANSI-C/64
bitfield​: ELF-64 executable object file - IA64

i = 0x00000000, low=0 , middle=0 , high=0
i = 0x80000000, low=4294967295, middle=0 , high=0
i = 0x80000001, low=4294967295, middle=0 , high=4294967295
i = 0x00000001, low=0 , middle=0 , high=4294967295

gcc/64
bitfield​: ELF-64 executable object file - IA64

i = 0x00000000, low=0 , middle=0 , high=0
i = 0x80000000, low=4294967295, middle=0 , high=0
i = 0x80000001, low=4294967295, middle=0 , high=4294967295
i = 0x00000001, low=0 , middle=0 , high=4294967295

HP-UX 11.23/64 U rx1620/64 Itanium 2/1600(2) ia64 2037 Mb

HP C-ANSI-C/64
bitfield​: ELF-64 executable object file - IA64

i = 0x00000000, low=0 , middle=0 , high=0
i = 0x80000000, low=4294967295, middle=0 , high=0
i = 0x80000001, low=4294967295, middle=0 , high=4294967295
i = 0x00000001, low=0 , middle=0 , high=4294967295

gcc/64
bitfield​: ELF-64 executable object file - IA64

i = 0x00000000, low=0 , middle=0 , high=0
i = 0x80000000, low=4294967295, middle=0 , high=0
i = 0x80000001, low=4294967295, middle=0 , high=4294967295
i = 0x00000001, low=0 , middle=0 , high=4294967295

HP-UX 11.11/64 U rp3410/64 PA8800/800(2) pa-2.0 4094 Mb

HP C-ANSI-C/64
cpp​: "bitfield.c", line 2​: error 4036​: Can't open include file 'stdint.h'.

gcc/64
bitfield​: ELF-64 executable object file - PA-RISC 2.0 (LP64)

i = 0x00000000, low=0 , middle=0 , high=0
i = 0x80000000, low=4294967295, middle=0 , high=0
i = 0x80000001, low=4294967295, middle=0 , high=4294967295
i = 0x00000001, low=0 , middle=0 , high=4294967295

So there would need to be (at least) two bitfield layouts provided to match
the current explicit bitshifts.

Make that at least three :)

Test program attached.

I think that that makes the currently proposed approach a non-starter.
Sorry.

There might be a way to do this, with one master source and regen scripts,
but I'm not sure how easy it is to be reliably portable.

Nicholas Clark

--
H.Merijn Brand http​://tux.nl Perl Monger http​://amsterdam.pm.org/
using perl5.00307 .. 5.19 porting perl5 on HP-UX, AIX, and openSUSE
http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org/
http​://qa.perl.org http​://www.goldmark.org/jeff/stupid-disclaimers/

@p5pRT
Copy link
Author

p5pRT commented Jun 9, 2014

From @tonycoz

On Mon May 26 01​:14​:00 2014, bulk88 wrote​:

On Tue May 20 16​:03​:31 2014, bulk88 wrote​:

This is a bug report for perl from bulk88@​hotmail.com,
generated with the help of perlbug 1.40 running under perl 5.20.0.

-----------------------------------------------------------------
[Please describe your issue here]

See attached patch.

Revised patched attached, tests + more features.

Based on the discussion (and I don't like it either), I'm rejecting this patch, and since the ticket is about the patch, the ticket.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jun 9, 2014

@tonycoz - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant