Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Remotely debug app with eclipse? Infinite loop issue

  • 21-01-2013 3:44pm
    #1
    Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,110 Mod ✭✭✭✭


    I want to step through my program as I'm having an issue but my app can't run when connected to the PC, I've ordered a wireless adapter but in the mean time I'd like to start the app connected to the PC, move it to a serial device and have my breakpoints work etc. I started my app in debug mode with a hit point of 10 but it didn't stop, how does one go about this?




    As for my problem, in my activity I have a method called sendOverSerial which just calls a library method to send data over usb to the device connected over serial.
    public static void sendOverSerial(byte[] data) {
    
            if(mSelectedAdapter !=null && data !=null){
            mSelectedAdapter.sendData(data);
    
          }}
    

    This activity opens an instance of a class, this class is used to write data to the terminal screen. Generally when I want to send data over serial, via the editText and buttons i call the sendOverSerial method in the activity. But when I am writing characters into the terminal itself they are picked up in this new instances write method. So I have to call the sendOverSerial method from that instance. My problem is that if I call it to write "TEST" below then TEST gets written to the terminal in an infinite loop, it just keeps writing it. Write is called over and over.
    public void write(byte[] bytes, int offset, int count) {
    
                int numCRs = 0;
                for (int i = offset; i < offset + count; ++i) {
                    if (bytes[i] == '\r') {
                        ++numCRs;
                    }
                }
    
                if (numCRs == 0) {
                    // No CRs -- just send data as-is
    
                    //infinite loop if I send from here
                    GraphicsTerminalActivity.sendOverSerial("TEST".getBytes());
    
                    super.write(bytes, offset, count);
    
                    if (isRunning()) {
                       doLocalEcho(bytes);
                    }
                    return;
                }
    
                Log.d(TAG, "CRs=== " + numCRs);
                // Convert CRs into CRLFs
                byte[] translated = new byte[count + numCRs];
                int j = 0;
                for (int i = offset; i < offset + count; ++i) {
                    if (bytes[i] == '\r') {
                        translated[j++] = '\r';
                        translated[j++] = '\n';
                    } else {
                        translated[j++] = bytes[i];
                    }
                }
               //fine if I send from here, sends once
                GraphicsTerminalActivity.sendOverSerial("SECOND TEST".getBytes());
               super.write(translated, 0, translated.length);
    
                // If server echo is off, echo the entered characters locally
                if (isRunning()) {
                    doLocalEcho(translated);
                }                            
            }
    

    Super.write from the library:
    public void write(byte[] data, int offset, int count) {
            try {
                mWriteQueue.write(data, offset, count);
            } catch (InterruptedException e) {
            }
            notifyNewOutput();
        }
    

    which then calls write in another class in the library, the bytequeue class
    public void write(byte[] buffer, int offset, int length)
        throws InterruptedException {
            if (length + offset > buffer.length) {
                throw
                    new IllegalArgumentException("length + offset > buffer.length");
            }
            if (length < 0) {
                throw
                new IllegalArgumentException("length < 0");
    
            }
            if (length == 0) {
                return;
            }
            synchronized(this) {
                int bufferLength = mBuffer.length;
                boolean wasEmpty = mStoredBytes == 0;
                while (length > 0) {
                    while(bufferLength == mStoredBytes) {
                        wait();
                    }
                    int tail = mHead + mStoredBytes;
                    int oneRun;
                    if (tail >= bufferLength) {
                        tail = tail - bufferLength;
                        oneRun = mHead - tail;
                    } else {
                        oneRun = bufferLength - tail;
                    }
                    int bytesToCopy = Math.min(oneRun, length);
                    System.arraycopy(buffer, offset, mBuffer, tail, bytesToCopy);
                    offset += bytesToCopy;
                    mStoredBytes += bytesToCopy;
                    length -= bytesToCopy;
                }
                if (wasEmpty) {
                    notify();
                }
            }
        }
    


    So I want some way to see why exactly the method is getting called over and over, stepping through it and log statements seem the best way.


Comments

  • Registered Users, Registered Users 2 Posts: 7,157 ✭✭✭srsly78


    You can run the debugger over wifi, I suggested this to you in another thread. http://forum.xda-developers.com/showthread.php?t=1685736

    PC doesn't need a wireless adapter if it's connected to the same lan via cable. Just note that some routers partition the wired vs wireless bits of the network. So long as they can ping each other it will be fine.

    See note at bottom of link above: "Jellybean has this function built in with android so you dont need root or run any commands from terminal" Not tried this myself.


Advertisement