Modifying the arguments to a function is a bad idea

F

Flash Gordon

jacob said:
Another "argument" that doesn't hold.

You can always restart the block by going to the start of the
function!

Not in the real word of embedded systems... at least not usefully on all
systems...
The function INTERFACE is a clear separation between parts of a
software. That interface should be held constant if possible.

OK, so please stop the incoming video from my camera from changing
whilst I restart the function that looks directly at the frame buffer
(the hardware has no mechanism to stop it being overwritten and not
enough memory to copy the image out of the incoming buffer)... yes, I
HAVE worked on real systems like that...

Or try and work out what is going on with a control loop by doing that
where the feedback is via not merely electrical systems, but mechanical
systems as well...

Or...

I've come across a fair few instances where the only way of debugging
the system would be to capture a limited amount of data over a long
period and plot it on a graph. I've even had to debug code where it was
a failure of certain values to be written to the RAM even though the
processor was trying to write them!

I'm sure that restarting a function *can* be useful in debugging certain
types of problems, but if I really needed to do that (and it is possible
due to not having too much state external to the function having
changed) I could just put it back to the state just before the function
was called so that the arguments get passed back in to the function! Or
I could look at the calling frame to work out what parameters were
passed in (I have done this).
 
A

Antoninus Twink

Nevertheless, observing speed limits is a good general rule.

Why?

Why not take responsibility for your own driving and select an
appropriate speed for the conditions, instead of living in a false
cocoon of "safety" because you are slavishly following a number on a
stick?

Why do you have such problems thinking for yourself, Heathfield?
 
J

jacob navia

Flash said:
OK, so please stop the incoming video from my camera from changing
whilst I restart the function that looks directly at the frame buffer
(the hardware has no mechanism to stop it being overwritten and not
enough memory to copy the image out of the incoming buffer)... yes, I
HAVE worked on real systems like that...


Geee How impressing pal...

I am speechless. WOW!!!

BUT

(Psss... You are in the debugger. So, your camera is still sending
stuff anyway, as you say, during the time when you look at the
name of the function the camera is still sending stuff.)

This is typical of contributions where the only objective is to
impress other people with "stories". Reminds me of the discussions
of old people where each one tells their hospitals horror stories...
Or try and work out what is going on with a control loop by doing that
where the feedback is via not merely electrical systems, but mechanical
systems as well...


Geee, how impressing. And when the software crashes, what happens?

Because, (as you know) software crashes do happen.

We were in the debugger remember?

This discussion is about how to easy the debugging tasks. Obviously
(like other "regulars" here), "Flash Gordon" never uses a debugger.

Discussion in this group reminds me of my school days, when each
told "stories" designed to represent the one telling it in
the most heroic way...

How far away from software engineering.

Or...

I've come across a fair few instances where the only way of debugging
the system would be to capture a limited amount of data over a long
period and plot it on a graph.

Heroic, yes. That is the word. The lone heroic story teller.
I've even had to debug code where it was
a failure of certain values to be written to the RAM even though the
processor was trying to write them!

Sure pal. You are a HERO!

But we were talking (at least I was talking) about how we can
write programs so that they are easier to debug. Among other
things, I proposed to avoid modifying the arguments so that
functions are restartable in the debugger. Obviously you
(as the other "regulars" like Mr Keighley) do not use a
debugger. Fine.

I'm sure that restarting a function *can* be useful in debugging certain
types of problems,
WOW!

but if I really needed to do that (and it is possible
due to not having too much state external to the function having
changed) I could just put it back to the state just before the function
was called so that the arguments get passed back in to the function!

Yes, but then you have to:

(1) jump to the end of the function
(2) Execute the epilogue
(3) then restart it when the call returns.

And all that could be avoided just by using a simple rule in the source
code.
Or
I could look at the calling frame to work out what parameters were
passed in (I have done this).

Sure, I have done that too so what? It is something that I do not like
to do since requires a lot of effort for nothing! I just modify
the function so that the parameters aren't changed and I spare myself
all that work.

But that is too much for an heroic "Flash Gordon"... obviously!

:)


Come on, grow up, will you?

jacob
 
P

Phil Carmody

Nick Keighley said:
posts should be standalone and understandable without
reading the subject line

What common and well accepted environment for reading usenet strips
subject lines from posts?

None, I'd wager.

I don't like people presuming that I *already* have the suject line
in my mind as I read a post, as indeed the subject lines are presented
to me in a completely different location in my newsreader, but one
whose body refers me to the subject line is perfectly acceptible, as
I can always get to the subject line trivially.

So - your problem seeing the subject line of a post was what?

Phil
 
F

Flash Gordon

jacob said:
Geee How impressing pal...

I am speechless. WOW!!!

You shouldn't be. You say you've worked on embedded systems so you
should be familiar with some of the other wonderful tools available.
BUT

(Psss... You are in the debugger. So, your camera is still sending
stuff anyway, as you say, during the time when you look at the
name of the function the camera is still sending stuff.)

No, I used a variety of tools *including* debuggers, but not debuggers
exclusively.
This is typical of contributions where the only objective is to
impress other people with "stories". Reminds me of the discussions
of old people where each one tells their hospitals horror stories...

I'm not that old, and some of the people I know who are that old are
more interested in learning things than you seem to be.
Geee, how impressing. And when the software crashes, what happens?

Well, on that particular piece of software I used a variety of methods...

Getting a hardware engineer to hook up a logic analyser and set up
tracing on specific items of data so I could monitor them over a long
period (a second being a very long time)...

Reading the comments in the code and comparing what was actually done to
what the comments said (which showed up several serious errors)...
Because, (as you know) software crashes do happen.

We were in the debugger remember?

No, I wasn't. That was not, on this occasion, the best tool I had available.
This discussion is about how to easy the debugging tasks. Obviously
(like other "regulars" here), "Flash Gordon" never uses a debugger.

I do use debuggers, I just don't use them all the time. Some times it is
not practical for all sorts of reasons, other times it is the fastest
method (if you get a segmentation violation it is the easiest way to see
what line of code and then work your way up the backtrace to see what
was passed in).
Discussion in this group reminds me of my school days, when each
told "stories" designed to represent the one telling it in
the most heroic way...

How far away from software engineering.

No, it's real software engineering in the real world where you use the
best tool available, which is not always a debugger.
Heroic, yes. That is the word. The lone heroic story teller.

No, it was very easy. Get the logic analyser hooked up, tell it to
capture the relevant data, tell it to plot it on a graph, then look at
the graph. After the initial setup of the logic analyser (which took the
hardware engineer a while) it was only a matter of minutes of work to
get data captured and graphed.
Sure pal. You are a HERO!

No, and I actually used a debugger to solve it. It's just that the
methods you describe were not appropriate. I set it to break on a
specific data value it should hit and found it didn't. Then I tried
another value, and with a bit of experimentation (restarting the
software from scratch each time because I knew memory was corrupted) I
found approximately when it was crashing. Since the software could
obviously not cause the effect being seen I did some experimentation
writing values to the RAM and found the patterns that were not working.
But we were talking (at least I was talking) about how we can
write programs so that they are easier to debug. Among other
things, I proposed to avoid modifying the arguments so that
functions are restartable in the debugger. Obviously you
(as the other "regulars" like Mr Keighley) do not use a
debugger. Fine.

I never said that I never use a debugger. I've never used the method you
described, and often it would not be practical for reasons nothing to do
with what you describe.

Perhaps rather than being sarcastic you should accept that your method
is only one of MANy methods of debugging. Some of us will use whichever
method seems most appropriate at any given time.
Yes, but then you have to:

(1) jump to the end of the function
(2) Execute the epilogue
(3) then restart it when the call returns.

And all that could be avoided just by using a simple rule in the source
code.

Or you avoid ALL of that by...
(1) reading the disassemble to see how much the stack pointer (or
whatever) has been adjusted and set it back
(2) set the program counter (or equivilent) to the address of the code
where the arguments are evaluated and placed in to the parameters
(3) do any other required adjustments (which you missed in your
description above)
(4) start stepping through it.

No need to finish running the current run.

Oh, and I have sometimes used a debugger to set up parameters and start
a specific function manually. In fact, on one project, that was how ALL
of our unit tests were implemented!

Sure, I have done that too so what?

Then you should know it is easy.
It is something that I do not like
to do since requires a lot of effort for nothing!

gdb> frame 1
Examine line of code which does the call
Copy the expression for the first parameter using the mouse. Press "p"
followed by the space key, then paste the expression and hit return.
Repeat for each of the other parameters.
Quick and simple.

You are the one who thinks debuggers are wonderful, so you should know
how to do simple things like this quickly and easily! If it isn't easy
in your debugger then perhaps your debugger needs a bit more work doing
on it!
I just modify
the function so that the parameters aren't changed and I spare myself
all that work.

Unless, as other people have pointed out (and you ignored) the optimiser
has done the sensible thing and reused the space (or register) when it
was no longer needed even though your code did not change the parameter.
Yes, some of us use optimisers on our code!
But that is too much for an heroic "Flash Gordon"... obviously!

:)

I may use the mane of a "super hero" as my nick, but there is nothing
heroic about any of the techniques I used.
Come on, grow up, will you?

I did a long time ago. Why don't you try it and learn that there are
other ways of doing things that are different.

I didn't even say that your method is never appropriate. I just said
that it is not always possible for any of a number of reasons.
 
K

Keith Thompson

Richard Heathfield said:
Flash Gordon said:

Neither did I. Note, however, that some people never learned to read
for comprehension.

That's an unjustified assumption. It's entirely possible they've
merely forgotten.
 
J

jacob navia

Nick said:

You said in message (in this thread)
> how do you "restart" a function? With a debugger?
> I never restart functions with a debugger

I thought that you belonged to the elite group of people here that
do not use debuggers or do not need debuggers (they do not have bugs)
or debug assembly through the phone, etc.

If you use a debugger, I can't understand that you never restart
a function that crashed to see why it crashed...

This is like:

you: "I have never set a breakpoint"
me: You do not use a debugger
you: LIAR!

And why you never restart a function?

It would use too much electricity?

or what?
 
J

jacob navia

Mark said:
I'm not sure I follow. You can't "go to the start" of a function except
by calling it again. In which case you can reset the parameter to
whatever you want. If you mean "rewind the debugger and rerun the
function", surely thats a QOI issue for the debugger- it should store
the complete state so it can rewind properly.

Imagine. At each function (sionce the debugger doesn't know if it
will crash) the debugger should stop the program, save the state
(that can be huge) and then go on in case the function crashes
and the user wants to go back!

[snip]
By the way, your mails are overly long. I'm a manager, I can't be
bothered to read more than the executive summary and I take the view
that if you can't summarise in a side of A4, you don't know what you're
talking about.

It shows that you feel that you are "a manager". It shows. You need
to be spoon feed :)


I will provide an "executive summary" for the posts that I want you to
read. Please disregard the others.

Thanks
 
B

bartc

Richard Heathfield said:
jacob navia said:


That must be a really elite group. In fact, I'm reasonably sure it's
empty.

I wouldn't have any idea of how to use a debugger, and I'm too old to learn.

(After debugging microprocessor circuits without test instruments, not even
a 'scope, writing machine code programs without even a keypad, and ...
nearly 30 years of other deprivations later, although I do have a keyboard
now .. you just learn to do without these things.)

So yes, the group of people who don't use debuggers, and are involved in
low-level-ish programming, is not quite empty.
 
N

Nick Keighley

You said in message (in this thread)
<dc58c775-c85a-4d1f-a858-18ea40647...@t13g2000yqt.googlegroups.com>
 > how do you "restart" a function? With a debugger?
 > I never restart functions with a debugger

I thought that you belonged to the elite group of people here that
do not use debuggers or do not need debuggers (they do not have bugs)
or debug assembly through the phone, etc.

I don't. Assuming such a group exists.

If you use a debugger, I can't understand that you never restart
a function that crashed to see why it crashed...

backtrace seems to work for me
This is like:

you:    "I have never set a breakpoint"

I have never said that. And it isn't true
me:      You do not use a debugger
you:     LIAR!

And why you never restart a function?

It would use too much electricity?

or what?

I don't see the point
 
T

Tom St Denis

You said in message (in this thread)
<dc58c775-c85a-4d1f-a858-18ea40647...@t13g2000yqt.googlegroups.com>
 > how do you "restart" a function? With a debugger?
 > I never restart functions with a debugger

I thought that you belonged to the elite group of people here that
do not use debuggers or do not need debuggers (they do not have bugs)
or debug assembly through the phone, etc.

If you use a debugger, I can't understand that you never restart
a function that crashed to see why it crashed...

This is like:

you:    "I have never set a breakpoint"
me:      You do not use a debugger
you:     LIAR!

And why you never restart a function?

It would use too much electricity?

or what?

THREAD-JACK!

Admittedly I'm mostly a lurker in clc but I seem to recall a time when
you [Jacob] were a cool cat, back when LCC was new and your LCC-win32
port was new, etc. WTF happened to make you want to fight with the
CLC regulars all the time?

Honestly, calm down, stop fighting with everyone. This is clc, not
clc.change.advocate or whatever. If you want language change
discussions [or best practices] take it elsewhere, and don't fight
with them either...

Tom
 
T

Tom St Denis

Me neither.

I don't think that that's a good thing to admit if you're a
professional software developer. Sure for the old timers who got
their start long before things like gdb were around that's less taboo,
but if you're <30 years old, a software developer, and don't at least
have some passing knowledge of how to use gdb [or it's god forsaken
msvc counterparts] you probably should invest in it.

The amount of times a backtrace or variable dump from gdb has
pinpointed a defect in a manner of seconds for me is enough to warrant
the few times where gdb is hopeless and can't resolve things [mostly
due to gcc not playing nice...].

Tom
 
R

Richard Bos

Keith Thompson said:
That's an unjustified assumption. It's entirely possible they've
merely forgotten.

Never attribute to ignorance a fault that must reasonably be explicable
only by malice.

Richard
 
F

Flash Gordon

jacob said:
Imagine. At each function (sionce the debugger doesn't know if it
will crash) the debugger should stop the program, save the state
(that can be huge) and then go on in case the function crashes
and the user wants to go back!

<snip>

I've used system where you could have a trace of exactly what has
happened going back certainly millions of instructions. I've heard of
systems that allow you to step backwards through the code a machine-code
instruction at a time, although I've never actually such systems.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top